private Collection<Long> decodeInvalid(BinaryDecoder decoder) throws IOException { int size = decoder.readInt(); Collection<Long> invalid = Lists.newArrayListWithCapacity(size); while (size != 0) { // zero denotes end of list as per AVRO spec for (int remaining = size; remaining > 0; --remaining) { invalid.add(decoder.readLong()); } size = decoder.readInt(); } return invalid; }
/** * Read a byte sequence. First read an int to indicate how many bytes to read, then that many bytes. * @return the read bytes as a byte array * @throws java.io.IOException If there is IO error. * @throws java.io.EOFException If end of file reached. */ public byte[] readBytes() throws IOException { int toRead = readInt(); byte[] bytes = new byte[toRead]; while (toRead > 0) { int byteRead = input.read(bytes, bytes.length - toRead, toRead); if (byteRead == -1) { throw new EOFException(); } toRead -= byteRead; } return bytes; }
private NavigableMap<Long, Set<ChangeId>> decodeChangeSets(BinaryDecoder decoder) throws IOException { int size = decoder.readInt(); NavigableMap<Long, Set<ChangeId>> changeSets = new TreeMap<Long, Set<ChangeId>>(); while (size != 0) { // zero denotes end of list as per AVRO spec for (int remaining = size; remaining > 0; --remaining) { changeSets.put(decoder.readLong(), decodeChanges(decoder)); } size = decoder.readInt(); } return changeSets; }
private Set<ChangeId> decodeChanges(BinaryDecoder decoder) throws IOException { int size = decoder.readInt(); HashSet<ChangeId> changes = Sets.newHashSetWithExpectedSize(size); while (size != 0) { // zero denotes end of list as per AVRO spec for (int remaining = size; remaining > 0; --remaining) { changes.add(new ChangeId(decoder.readBytes())); } size = decoder.readInt(); } // todo is there an immutable hash set? return changes; } }
private SnapshotCodec getCodec(InputStream in) { BinaryDecoder decoder = new BinaryDecoder(in); int persistedVersion; try { persistedVersion = decoder.readInt(); } catch (IOException e) { LOG.error("Unable to read transaction state version: ", e); throw Throwables.propagate(e); } return getCodecForVersion(persistedVersion); }
protected NavigableMap<Long, TransactionManager.InProgressTx> decodeInProgress(BinaryDecoder decoder) throws IOException { int size = decoder.readInt(); NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap(); while (size != 0) { // zero denotes end of list as per AVRO spec for (int remaining = size; remaining > 0; --remaining) { long txId = decoder.readLong(); long expiration = decoder.readLong(); long visibilityUpperBound = decoder.readLong(); inProgress.put(txId, new TransactionManager.InProgressTx(visibilityUpperBound, expiration)); } size = decoder.readInt(); } return inProgress; }
throws IOException { int size = decoder.readInt(); NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap(); while (size != 0) { // zero denotes end of list as per AVRO spec long expiration = decoder.readLong(); long visibilityUpperBound = decoder.readLong(); int txTypeIdx = decoder.readInt(); TransactionManager.InProgressType txType; try { int checkpointPointerSize = decoder.readInt(); LongArrayList checkpointPointers = new LongArrayList(checkpointPointerSize); while (checkpointPointerSize != 0) { checkpointPointers.add(decoder.readLong()); checkpointPointerSize = decoder.readInt(); size = decoder.readInt();
@Override protected NavigableMap<Long, TransactionManager.InProgressTx> decodeInProgress(BinaryDecoder decoder) throws IOException { int size = decoder.readInt(); NavigableMap<Long, TransactionManager.InProgressTx> inProgress = Maps.newTreeMap(); while (size != 0) { // zero denotes end of list as per AVRO spec for (int remaining = size; remaining > 0; --remaining) { long txId = decoder.readLong(); long expiration = decoder.readLong(); long visibilityUpperBound = decoder.readLong(); int txTypeIdx = decoder.readInt(); TransactionManager.InProgressType txType; try { txType = TransactionManager.InProgressType.values()[txTypeIdx]; } catch (ArrayIndexOutOfBoundsException e) { throw new IOException("Type enum ordinal value is out of range: " + txTypeIdx); } inProgress.put(txId, new TransactionManager.InProgressTx(visibilityUpperBound, expiration, txType, new LongArrayList())); } size = decoder.readInt(); } return inProgress; } }