Methods Summary |
---|
public void | close()Closes this stream to further operations.
flush();
|
protected final void | flush()Forces any buffered output to be written.
flushBuffer(buffer, bufferPosition);
bufferStart += bufferPosition;
bufferPosition = 0;
|
protected abstract void | flushBuffer(byte[] b, int len)Expert: implements buffer write. Writes bytes at the current position in
the output.
|
public final long | getFilePointer()Returns the current position in this file, where the next write will
occur.
return bufferStart + bufferPosition;
|
public abstract long | length()The number of bytes in the file.
|
public void | seek(long pos)Sets current position in this file, where the next write will occur.
flush();
bufferStart = pos;
|
public final void | writeByte(byte b)Writes a single byte. // position in buffer
if (bufferPosition >= BUFFER_SIZE)
flush();
buffer[bufferPosition++] = b;
|
public final void | writeBytes(byte[] b, int length)Writes an array of bytes.
for (int i = 0; i < length; i++)
writeByte(b[i]);
|
public final void | writeChars(java.lang.String s, int start, int length)Writes a sequence of UTF-8 encoded characters from a string.
final int end = start + length;
for (int i = start; i < end; i++) {
final int code = (int)s.charAt(i);
if (code >= 0x01 && code <= 0x7F)
writeByte((byte)code);
else if (((code >= 0x80) && (code <= 0x7FF)) || code == 0) {
writeByte((byte)(0xC0 | (code >> 6)));
writeByte((byte)(0x80 | (code & 0x3F)));
} else {
writeByte((byte)(0xE0 | (code >>> 12)));
writeByte((byte)(0x80 | ((code >> 6) & 0x3F)));
writeByte((byte)(0x80 | (code & 0x3F)));
}
}
|
public final void | writeInt(int i)Writes an int as four bytes.
writeByte((byte)(i >> 24));
writeByte((byte)(i >> 16));
writeByte((byte)(i >> 8));
writeByte((byte) i);
|
public final void | writeLong(long i)Writes a long as eight bytes.
writeInt((int) (i >> 32));
writeInt((int) i);
|
public final void | writeString(java.lang.String s)Writes a string.
int length = s.length();
writeVInt(length);
writeChars(s, 0, length);
|
public final void | writeVInt(int i)Writes an int in a variable-length format. Writes between one and
five bytes. Smaller values take fewer bytes. Negative numbers are not
supported.
while ((i & ~0x7F) != 0) {
writeByte((byte)((i & 0x7f) | 0x80));
i >>>= 7;
}
writeByte((byte)i);
|
public final void | writeVLong(long i)Writes an long in a variable-length format. Writes between one and five
bytes. Smaller values take fewer bytes. Negative numbers are not
supported.
while ((i & ~0x7F) != 0) {
writeByte((byte)((i & 0x7f) | 0x80));
i >>>= 7;
}
writeByte((byte)i);
|