out.writeInt(outWithPos.getPosition()); if (!ignoreTypeSerializerSerialization) { TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot( outViewWrapper, (TypeSerializerSnapshot) entry.getValue().f1, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); if (!ignoreTypeSerializerSerialization) { TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot( outViewWrapper, (TypeSerializerSnapshot) entry.getValue().f1, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); if (!ignoreTypeSerializerSerialization) { TypeSerializerSerializationUtil.writeSerializer(outViewWrapper, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot( outViewWrapper, (TypeSerializerSnapshot) entry.getValue().f1, entry.getValue().f0); out.writeInt(outWithPos.getPosition()); out.write(outWithPos.getBuf(), 0 , outWithPos.getPosition());
out.writeInt(bufferWithPos.getPosition()); writeSerializer(bufferWrapper, serAndConfSnapshot.f0); out.writeInt(bufferWithPos.getPosition()); TypeSerializerSnapshotSerializationUtil.writeSerializerSnapshot( bufferWrapper, (TypeSerializerSnapshot) serAndConfSnapshot.f1, serAndConfSnapshot.f0); out.writeInt(bufferWithPos.getPosition()); out.write(bufferWithPos.getBuf(), 0, bufferWithPos.getPosition());
@Override public void write(DataOutputView out) throws IOException { super.write(out); if (typeSerializer instanceof UnloadableDummyTypeSerializer) { UnloadableDummyTypeSerializer<T> dummyTypeSerializer = (UnloadableDummyTypeSerializer<T>) this.typeSerializer; byte[] serializerBytes = dummyTypeSerializer.getActualBytes(); out.write(serializerBytes.length); out.write(serializerBytes); } else { // write in a way that allows the stream to recover from exceptions try (ByteArrayOutputStreamWithPos streamWithPos = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(streamWithPos, typeSerializer); out.writeInt(streamWithPos.getPosition()); out.write(streamWithPos.getBuf(), 0, streamWithPos.getPosition()); } } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }
/** * Test setting position which is exactly the same with the buffer size. */ @Test public void testSetPositionWhenBufferIsFull() throws Exception { stream.write(new byte[BUFFER_SIZE]); // check whether the buffer is filled fully Assert.assertEquals(BUFFER_SIZE, stream.getBuf().length); // check current position is the end of the buffer Assert.assertEquals(BUFFER_SIZE, stream.getPosition()); stream.setPosition(BUFFER_SIZE); // confirm current position is at where we expect. Assert.assertEquals(BUFFER_SIZE, stream.getPosition()); }
/** * Test setting position larger than buffer size. */ @Test public void testSetPositionLargerThanBufferSize() throws Exception { // fully fill the buffer stream.write(new byte[BUFFER_SIZE]); Assert.assertEquals(BUFFER_SIZE, stream.getBuf().length); // expand the buffer by setting position beyond the buffer length stream.setPosition(BUFFER_SIZE + 1); Assert.assertEquals(BUFFER_SIZE * 2, stream.getBuf().length); Assert.assertEquals(BUFFER_SIZE + 1, stream.getPosition()); }
prev = end + 1; for (int kg : offsets.getKeyGroupRange()) { offsets.setKeyGroupOffset(kg, out.getPosition()); dov.writeInt(kg); ++writtenKeyGroups; LongArrayList offsets = new LongArrayList(size); for (int s = 0; s < size; ++s) { offsets.add(out.getPosition()); int val = i * NUM_HANDLES + s; dov.writeInt(val);
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
@Override public long getPos() throws IOException { return os.getPosition(); }
private static void writeLengthFrom( int fromPosition, ByteArrayOutputStreamWithPos keySerializationStream, DataOutputView keySerializationDateDataOutputView) throws IOException { int length = keySerializationStream.getPosition() - fromPosition; writeVariableIntBytes(length, keySerializationDateDataOutputView); }
private static void writeLengthFrom( int fromPosition, ByteArrayOutputStreamWithPos keySerializationStream, DataOutputView keySerializationDateDataOutputView) throws IOException { int length = keySerializationStream.getPosition() - fromPosition; writeVariableIntBytes(length, keySerializationDateDataOutputView); }
private void writeNameSpace( N namespace, ByteArrayOutputStreamWithPos keySerializationStream, DataOutputView keySerializationDataOutputView) throws IOException { int beforeWrite = keySerializationStream.getPosition(); namespaceSerializer.serialize(namespace, keySerializationDataOutputView); if (ambiguousKeyPossible) { //write length of namespace writeLengthFrom(beforeWrite, keySerializationStream, keySerializationDataOutputView); } }
private void writeKey( K key, ByteArrayOutputStreamWithPos keySerializationStream, DataOutputView keySerializationDataOutputView) throws IOException { //write key int beforeWrite = keySerializationStream.getPosition(); backend.getKeySerializer().serialize(key, keySerializationDataOutputView); if (ambiguousKeyPossible) { //write size of key writeLengthFrom(beforeWrite, keySerializationStream, keySerializationDataOutputView); } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }
@Override protected void writeKeyAndNamespaceSerializers(DataOutputView out) throws IOException { // the pre-versioned format only serializes the serializers, without their configuration snapshots try (ByteArrayOutputStreamWithPos stream = new ByteArrayOutputStreamWithPos()) { InstantiationUtil.serializeObject(stream, timersSnapshot.getKeySerializer()); InstantiationUtil.serializeObject(stream, timersSnapshot.getNamespaceSerializer()); out.write(stream.getBuf(), 0, stream.getPosition()); } } }