assertEquals(written, counter.getCount()); counter.write(0); written += 1; assertEquals(written, out.size()); counter.write(data); written += 10; assertEquals(written, out.size()); assertEquals(written, counter.getCount()); counter.write(data, 0, 5); written += 5; assertEquals(written, out.size()); assertEquals(written, counter.getCount()); counter.write(data, 2, 5); written += 5; assertEquals(written, out.size()); counter.write(data, 0, data.length + 1); fail("expected exception"); } catch (IndexOutOfBoundsException expected) {
@Override public void write(final byte[] b, final int off, final int len) throws IOException { outputStream.write(b, off, len); }
/** * Writes the specified byte to this output stream. The general * contract for <code>write</code> is that one byte is written * to the output stream. The byte to be written is the eight * low-order bits of the argument <code>b</code>. The 24 * high-order bits of <code>b</code> are ignored. * <p> * Subclasses of <code>OutputStream</code> must provide an * implementation for this method. * </p> * * @param b the <code>byte</code>. * @throws java.io.IOException if an I/O error occurs. In particular, * an <code>IOException</code> may be thrown if the * output stream has been closed. */ @Override public void write(int b) throws IOException { outputStream.write(b); }
void write(TableRow value) throws Exception { CODER.encode(value, out, Context.OUTER); out.write(NEWLINE); }
public void write(T objectToWrite) throws IOException { if (prevObject != null && strategy.compare(prevObject, objectToWrite) >= 0) { objectsSorted = false; } byte[] bytesToWrite = strategy.toBytes(objectToWrite); ++numWritten; valuesOut.write(Ints.toByteArray(bytesToWrite.length)); valuesOut.write(bytesToWrite); headerOut.write(Ints.toByteArray((int) valuesOut.getCount())); prevObject = objectToWrite; }
_auditLogOut.write('\n');
_auditLogOut.write('\n');
@Override public void close() throws IOException { final byte numBytesForMax = VSizeIndexedInts.getNumBytesForMax(maxId); valuesOut.write(new byte[4 - numBytesForMax]); Closeables.close(headerOut, false); Closeables.close(valuesOut, false); final long numBytesWritten = headerOut.getCount() + valuesOut.getCount(); Preconditions.checkState( headerOut.getCount() == (numWritten * 4), "numWritten[%s] number of rows should have [%s] bytes written to headerOut, had[%s]", numWritten, numWritten * 4, headerOut.getCount() ); Preconditions.checkState( numBytesWritten < Integer.MAX_VALUE, "Wrote[%s] bytes, which is too many.", numBytesWritten ); OutputStream metaOut = ioPeon.makeOutputStream(makeFilename("meta")); try { metaOut.write(new byte[]{version, numBytesForMax}); metaOut.write(Ints.toByteArray((int) numBytesWritten + 4)); metaOut.write(Ints.toByteArray(numWritten)); } finally { metaOut.close(); } }
} else { countingStream.write(',');
assertEquals(written, counter.getCount()); counter.write(0); written += 1; assertEquals(written, out.size()); counter.write(data); written += 10; assertEquals(written, out.size()); assertEquals(written, counter.getCount()); counter.write(data, 0, 5); written += 5; assertEquals(written, out.size()); assertEquals(written, counter.getCount()); counter.write(data, 2, 5); written += 5; assertEquals(written, out.size()); counter.write(data, 0, data.length + 1); fail("expected exception"); } catch (IndexOutOfBoundsException expected) {