|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.simantics.databoard.util.binary.BinaryFile
public class BinaryFile
This class is a Random Access File implementation to RandomAccessBinary. The implementation is buffered. The implementation is not multi-thread safe.
There is a buffer used for reading and writing. It has a buffer read and write position. When read, the buffer is filled. When written, the buffer is written. When the file pointer is moved, the file size changed or flushed the buffers are cleared. If there were unwritten bytes, they are flushed to disc.
There is internal pointer variable. The actual file pointer is moved on disc read and write operations.
Primitive number writes (int, short, char, double, float and long) and
written in big endian (network) byte order. Use Endian
to make little endian operations.
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface org.simantics.databoard.util.binary.RandomAccessBinary |
---|
RandomAccessBinary.ByteSide |
Constructor Summary | |
---|---|
BinaryFile(java.io.File file)
|
|
BinaryFile(java.io.File file,
int bufSize)
|
|
BinaryFile(java.io.File file,
java.lang.String mode)
|
|
BinaryFile(java.io.RandomAccessFile file)
|
|
BinaryFile(java.io.RandomAccessFile file,
int bufSize)
|
Method Summary | |
---|---|
void |
close()
Closes the object. |
java.io.File |
file()
|
void |
flush()
Flushes internal buffer |
java.io.RandomAccessFile |
getRandomAccessFile()
|
void |
insertBytes(long bytes,
RandomAccessBinary.ByteSide side)
Insert bytes at current pointer. |
static void |
insertBytes(java.io.RandomAccessFile file,
long position,
long bytes)
Inserts bytes into a middle of a file. |
boolean |
isOpen()
Check if binary is open. |
long |
length()
Get the length of the binary object. |
long |
position()
Get the position of the cursor |
void |
position(long newPosition)
Set new cursor position. |
boolean |
readBoolean()
|
byte |
readByte()
|
char |
readChar()
|
double |
readDouble()
|
float |
readFloat()
|
void |
readFully(byte[] dst)
|
void |
readFully(byte[] dst,
int offset,
int length)
|
void |
readFully(java.nio.ByteBuffer buf)
Read buf fully |
void |
readFully(java.nio.ByteBuffer buf,
int length)
Read fully length bytes |
int |
readInt()
|
java.lang.String |
readLine()
|
long |
readLong()
|
short |
readShort()
|
int |
readUnsignedByte()
|
int |
readUnsignedShort()
|
java.lang.String |
readUTF()
|
void |
removeBytes(long bytes,
RandomAccessBinary.ByteSide side)
Remove bytes from the position of the current pointer. |
static void |
removeBytes(java.io.RandomAccessFile file,
long position,
long bytes)
Remove bytes from a file |
void |
reset()
Clears read&write buffer. |
void |
setLength(long newLength)
Set length of the binary object. |
int |
skipBytes(int bytes)
|
long |
skipBytes(long bytes)
|
static BinaryFile |
tempFile(long size)
|
java.lang.String |
toString()
|
void |
write(byte[] src)
|
void |
write(byte[] src,
int offset,
int length)
|
void |
write(int b)
|
void |
writeBoolean(boolean v)
|
void |
writeByte(int b)
|
void |
writeBytes(java.lang.String s)
|
void |
writeChar(int value)
|
void |
writeChars(java.lang.String s)
|
void |
writeDouble(double value)
|
void |
writeFloat(float value)
|
void |
writeFully(java.nio.ByteBuffer src)
Put n bytes from the remaining of the byte array. |
void |
writeFully(java.nio.ByteBuffer src,
int length)
Put n bytes from the remaining of the byte buffer. |
void |
writeInt(int value)
|
void |
writeLong(long value)
|
void |
writeShort(int value)
|
void |
writeUTF(java.lang.String s)
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public BinaryFile(java.io.RandomAccessFile file) throws java.io.IOException
java.io.IOException
public BinaryFile(java.io.File file) throws java.io.IOException
java.io.IOException
public BinaryFile(java.io.File file, java.lang.String mode) throws java.io.IOException
java.io.IOException
public BinaryFile(java.io.RandomAccessFile file, int bufSize) throws java.io.IOException
java.io.IOException
public BinaryFile(java.io.File file, int bufSize) throws java.io.IOException
java.io.IOException
Method Detail |
---|
public static BinaryFile tempFile(long size) throws java.io.IOException
java.io.IOException
public void close() throws java.io.IOException
close
in interface RandomAccessBinary
java.io.IOException
public boolean isOpen()
RandomAccessBinary
isOpen
in interface RandomAccessBinary
public java.io.File file()
public java.io.RandomAccessFile getRandomAccessFile()
public byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
public char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
public int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
public boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] dst, int offset, int length) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(byte[] dst) throws java.io.IOException
readFully
in interface java.io.DataInput
java.io.IOException
public void readFully(java.nio.ByteBuffer buf) throws java.io.IOException
BinaryReadable
readFully
in interface BinaryReadable
java.io.IOException
public void readFully(java.nio.ByteBuffer buf, int length) throws java.io.IOException
BinaryReadable
readFully
in interface BinaryReadable
java.io.IOException
public double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
public float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
public int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
public long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
public short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
public int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
public final java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
public final java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
public long position()
RandomAccessBinary
position
in interface BinaryReadable
position
in interface RandomAccessBinary
public void position(long newPosition)
RandomAccessBinary
position
in interface RandomAccessBinary
public void flush() throws java.io.IOException
flush
in interface BinaryWriteable
flush
in interface RandomAccessBinary
java.io.IOException
public void reset() throws java.io.IOException
reset
in interface RandomAccessBinary
java.io.IOException
public long skipBytes(long bytes) throws java.io.IOException
skipBytes
in interface BinaryReadable
java.io.IOException
public int skipBytes(int bytes) throws java.io.IOException
skipBytes
in interface java.io.DataInput
java.io.IOException
public void write(int b) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void writeByte(int b) throws java.io.IOException
writeByte
in interface java.io.DataOutput
java.io.IOException
public void writeBoolean(boolean v) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
java.io.IOException
public void writeFully(java.nio.ByteBuffer src) throws java.io.IOException
BinaryWriteable
writeFully
in interface BinaryWriteable
java.io.IOException
public void writeFully(java.nio.ByteBuffer src, int length) throws java.io.IOException
BinaryWriteable
writeFully
in interface BinaryWriteable
java.io.IOException
public void write(byte[] src, int offset, int length) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void write(byte[] src) throws java.io.IOException
write
in interface java.io.DataOutput
java.io.IOException
public void writeDouble(double value) throws java.io.IOException
writeDouble
in interface java.io.DataOutput
java.io.IOException
public void writeFloat(float value) throws java.io.IOException
writeFloat
in interface java.io.DataOutput
java.io.IOException
public void writeInt(int value) throws java.io.IOException
writeInt
in interface java.io.DataOutput
java.io.IOException
public void writeLong(long value) throws java.io.IOException
writeLong
in interface java.io.DataOutput
java.io.IOException
public void writeShort(int value) throws java.io.IOException
writeShort
in interface java.io.DataOutput
java.io.IOException
public void writeChar(int value) throws java.io.IOException
writeChar
in interface java.io.DataOutput
java.io.IOException
public void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface java.io.DataOutput
java.io.IOException
public void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface java.io.DataOutput
java.io.IOException
public void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface java.io.DataOutput
java.io.IOException
public void insertBytes(long bytes, RandomAccessBinary.ByteSide side) throws java.io.IOException
RandomAccessBinary
insertBytes
in interface RandomAccessBinary
java.io.IOException
public void removeBytes(long bytes, RandomAccessBinary.ByteSide side) throws java.io.IOException
RandomAccessBinary
removeBytes
in interface RandomAccessBinary
java.io.IOException
public long length() throws java.io.IOException
RandomAccessBinary
length
in interface BinaryReadable
length
in interface RandomAccessBinary
java.io.IOException
public void setLength(long newLength) throws java.io.IOException
RandomAccessBinary
setLength
in interface RandomAccessBinary
java.io.IOException
public static void insertBytes(java.io.RandomAccessFile file, long position, long bytes) throws java.io.IOException
file
- fileposition
- bytes
-
java.io.IOException
public static void removeBytes(java.io.RandomAccessFile file, long position, long bytes) throws java.io.IOException
file
- position
- bytes
-
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |