public synchronized void write(int oneByte) throws IOException {
byte[] internalBuffer = buf;
if (internalBuffer == null) {
throw new IOException(Messages.getString("luni.24")); //$NON-NLS-1$
}
if (count == internalBuffer.length) {
out.write(internalBuffer, 0, count);
count = 0;
}
internalBuffer[count++] = (byte) oneByte;
}
Writes one byte to this stream. Only the low order byte of the integer
{@code oneByte} is written. If there is room in the buffer, the byte is
copied into the buffer and the count incremented. Otherwise, the buffer
plus {@code oneByte} are written to the target stream, the target is
flushed, and the buffer is reset. |
public synchronized void write(byte[] buffer,
int offset,
int length) throws IOException {
byte[] internalBuffer = buf;
if (internalBuffer == null) {
throw new IOException(Messages.getString("luni.24")); //$NON-NLS-1$
}
if (buffer == null) {
// luni.11=buffer is null
throw new NullPointerException(Messages.getString("luni.11")); //$NON-NLS-1$
}
if (length >= internalBuffer.length) {
flushInternal();
out.write(buffer, offset, length);
return;
}
if (offset < 0 || offset > buffer.length - length) {
// luni.12=Offset out of bounds \: {0}
throw new ArrayIndexOutOfBoundsException(Messages.getString("luni.12", offset)); //$NON-NLS-1$
}
if (length < 0) {
// luni.18=Length out of bounds \: {0}
throw new ArrayIndexOutOfBoundsException(Messages.getString("luni.18", length)); //$NON-NLS-1$
}
// flush the internal buffer first if we have not enough space left
if (length >= (internalBuffer.length - count)) {
flushInternal();
}
// the length is always less than (internalBuffer.length - count) here so arraycopy is safe
System.arraycopy(buffer, offset, internalBuffer, count, length);
count += length;
}
Writes {@code count} bytes from the byte array {@code buffer} starting at
{@code offset} to this stream. If there is room in the buffer to hold the
bytes, they are copied in. If not, the buffered bytes plus the bytes in
{@code buffer} are written to the target stream, the target is flushed,
and the buffer is cleared. |