@Override public OutputStream subStream(int streamPosition, int length) { return new FixedByteArrayOutputStream(this.array, this.offset + streamPosition, length); }
Arrays.fill(buffer, (byte) 0); try (FixedByteArrayOutputStream os = new FixedByteArrayOutputStream(buffer, startOffset, length)) { os.write(i); os.write(secondHalf); () -> os.write(255), ex -> ex instanceof IOException); () -> os.write(new byte[10]), ex -> ex instanceof IOException);
@Override @SneakyThrows(IOException.class) protected byte[] getData(FixedByteArrayOutputStream stream) { val b = stream.getData(); return StreamHelpers.readAll(b.getReader(), b.getLength()); } }
@Override @SneakyThrows(IOException.class) protected byte[] getData(FixedByteArrayOutputStream stream) { val b = stream.getData(); return StreamHelpers.readAll(b.getReader(), b.getLength()); } }
@Override public OutputStream subStream(int streamPosition, int length) { return new FixedByteArrayOutputStream(this.buf, streamPosition, length); }
/** * Creates an OutputStream that can be used to write contents to this ByteArraySegment. The OutputStream returned * is a FixedByteArrayOutputStream (ByteArrayOutputStream that cannot expand) that spans the entire ByteArraySegment. * * @return The OutputStream. * @throws IllegalStateException If the ByteArraySegment is readonly. */ public OutputStream getWriter() { Preconditions.checkState(!this.readOnly, "Cannot modify a read-only ByteArraySegment."); return new FixedByteArrayOutputStream(this.array, this.startOffset, this.length); }
@Override protected FixedByteArrayOutputStream createInstance(byte[] initialData) { return new FixedByteArrayOutputStream(initialData, 0, initialData.length); }
@Override protected FixedByteArrayOutputStream createInstance(byte[] initialData) { return new FixedByteArrayOutputStream(initialData, 0, initialData.length); }
@SneakyThrows(IOException.class) byte[] getFullSerialization() { byte[] result = new byte[Long.BYTES + Integer.BYTES + this.data.length]; serialize(new FixedByteArrayOutputStream(result, 0, result.length)); return result; }
/** * Tests the RandomRevisionDataOutput class with an fixed-length RandomAccessOutputStream. */ @Test public void testRandomOutputFixed() throws Exception { final int bufferSize = 1024 * 1024; @Cleanup val s = new FixedByteArrayOutputStream(new byte[bufferSize], 0, bufferSize); @Cleanup val impl = RevisionDataOutputStream.wrap(s); testImpl(impl, s::getData); }
appendOperations.add(appendOp); byte[] ad = new byte[(int) appendOp.getLength()]; getAppendData(appendOp, new FixedByteArrayOutputStream(ad, 0, ad.length), context); appendData.add(new ByteArrayInputStream(ad)); writtenData.write(ad);