📄 jfbinaryreader.java
字号:
/**
* $Id: JFBinaryReader.java $
*
* Copyright 2004 ~ 2005 JingFei International Cooperation LTD. All rights reserved.
*
*/
package com.jfimagine.utils.io;
import java.io.IOException;
import java.io.DataInputStream;
/**
* JFBinaryReader is a binary reader class to handle JFDraw files reading.
*
* @author CookieMaker
*
* @version $Revision: 1.6.0 $
*/
public class JFBinaryReader implements JFReader{
/**A data input object to read data*/
private DataInputStream m_dataInput;
/**
* Constructor of JFBinaryReader
*
*
*/
public JFBinaryReader(DataInputStream dataInput){
m_dataInput =dataInput;
}
/**
* Reads up to <code>len</code> bytes of data from the contained
* input stream into an array of bytes. An attempt is made to read
* as many as <code>len</code> bytes, but a smaller number may be read,
* possibly zero. The number of bytes actually read is returned as an
* integer.
*
*
* @param b the buffer into which the data is read.
* @param off the start offset of the data.
* @param len the maximum number of bytes read.
* @return the total number of bytes read into the buffer, or
* <code>-1</code> if there is no more data because the end
* of the stream has been reached.
* @exception IOException if an I/O error occurs.
*/
public int read(byte b[], int off, int len) throws IOException{
return m_dataInput.read(b,off,len);
}
/**
* Makes an attempt to skip over
* <code>n</code> bytes
* of data from the input
* stream, discarding the skipped bytes.
*
* The actual
* number of bytes skipped is returned.
*
* @param n the number of bytes to be skipped.
* @return the number of bytes actually skipped.
* @exception IOException if an I/O error occurs.
*/
public int skipBytes(int n) throws IOException{
return m_dataInput.skipBytes(n);
}
/**
* Reads one input byte and returns
* <code>true</code> if that byte is nonzero,
* <code>false</code> if that byte is zero.
* This method is suitable for reading
* the byte written by the <code>writeBoolean</code>
* method in JFWriter.
*
* @return the <code>boolean</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public boolean readBoolean() throws IOException{
return m_dataInput.readBoolean();
}
/**
* Reads and returns one input byte.
* The byte is treated as a signed value in
*
* This method is suitable for
* reading the byte written by the <code>writeByte</code>
* method in JFWriter.
*
* @return the 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public byte readByte() throws IOException{
return m_dataInput.readByte();
}
/**
* Reads one input byte, zero-extends
* it to type <code>int</code>, and returns
* the result, which is therefore in the range
* <code>0</code>
* through <code>255</code>.
* This method is suitable for reading
* the byte written by the <code>writeByte</code>
* method in JFWriter.
*
* @return the unsigned 8-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readUnsignedByte() throws IOException{
return m_dataInput.readUnsignedByte();
}
/**
* Reads two input bytes and returns
* a <code>short</code> value.
*
* This method
* is suitable for reading the bytes written
* by the <code>writeShort</code> method in JFWriter.
*
* @return the 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public short readShort() throws IOException{
return m_dataInput.readShort();
}
/**
* Reads two input bytes and returns
* an <code>int</code> value in the range <code>0</code>
* through <code>65535</code>.
*
* This method is suitable for reading the bytes
* written by the <code>writeShort</code> method in JFWriter.
*
* @return the unsigned 16-bit value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readUnsignedShort() throws IOException{
return m_dataInput.readUnsignedShort();
}
/**
* Reads an input <code>char</code> and returns the <code>char</code> value.
*
* This method
* is suitable for reading bytes written by
* the <code>writeChar</code> method in JFWriter.
*
* @return the Unicode <code>char</code> read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public char readChar() throws IOException{
return m_dataInput.readChar();
}
/**
* Reads four input bytes and returns an
* <code>int</code> value.
*
* This method is suitable
* for reading bytes written by the <code>writeInt</code>
* method in JFWriter.
*
* @return the <code>int</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public int readInt() throws IOException{
return m_dataInput.readInt();
}
/**
* Reads eight input bytes and returns
* a <code>long</code> value.
*
* This method is suitable
* for reading bytes written by the <code>writeLong</code>
* method in JFWriter.
*
* @return the <code>long</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public long readLong() throws IOException{
return m_dataInput.readLong();
}
/**
* Reads four input bytes and returns
* a <code>float</code> value.
*
* This method is suitable for reading
* bytes written by the <code>writeFloat</code>
* method in JFWriter.
*
* @return the <code>float</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public float readFloat() throws IOException{
return m_dataInput.readFloat();
}
/**
* Reads eight input bytes and returns
* a <code>double</code> value.
*
* This method is suitable for reading
* bytes written by the <code>writeDouble</code>
* method in JFWriter.
*
* @return the <code>double</code> value read.
* @exception EOFException if this stream reaches the end before reading
* all the bytes.
* @exception IOException if an I/O error occurs.
*/
public double readDouble() throws IOException{
return m_dataInput.readDouble();
}
/**
* Reads in a string that has been encoded using a modified UTF-8 format.
* <p>
* The <code>writeUTF</code>
* method in JFWriter may be used to write data that is suitable
* for reading by this method.
* @return a Unicode string.
* @exception EOFException if this stream reaches the end
* before reading all the bytes.
* @exception IOException if an I/O error occurs.
* @exception UTFDataFormatException if the bytes do not represent a
* valid UTF-8 encoding of a string.
*/
public String readUTF() throws IOException{
return m_dataInput.readUTF();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -