/** * This read attempts to first identify if the input view contains the special * {@link #VERSIONED_IDENTIFIER} by reading and buffering the first few bytes. * If identified to be versioned, the usual version resolution read path * in {@link VersionedIOReadableWritable#read(DataInputView)} is invoked. * Otherwise, we "reset" the input stream by pushing back the read buffered bytes * into the stream. */ public final void read(InputStream inputStream) throws IOException { byte[] tmp = new byte[VERSIONED_IDENTIFIER.length]; inputStream.read(tmp); if (Arrays.equals(tmp, VERSIONED_IDENTIFIER)) { DataInputView inputView = new DataInputViewStreamWrapper(inputStream); super.read(inputView); read(inputView, true); } else { PushbackInputStream resetStream = new PushbackInputStream(inputStream, VERSIONED_IDENTIFIER.length); resetStream.unread(tmp); read(new DataInputViewStreamWrapper(resetStream), false); } }
/** * This read attempts to first identify if the input view contains the special * {@link #VERSIONED_IDENTIFIER} by reading and buffering the first few bytes. * If identified to be versioned, the usual version resolution read path * in {@link VersionedIOReadableWritable#read(DataInputView)} is invoked. * Otherwise, we "reset" the input stream by pushing back the read buffered bytes * into the stream. */ public final void read(InputStream inputStream) throws IOException { byte[] tmp = new byte[VERSIONED_IDENTIFIER.length]; inputStream.read(tmp); if (Arrays.equals(tmp, VERSIONED_IDENTIFIER)) { DataInputView inputView = new DataInputViewStreamWrapper(inputStream); super.read(inputView); read(inputView, true); } else { PushbackInputStream resetStream = new PushbackInputStream(inputStream, VERSIONED_IDENTIFIER.length); resetStream.unread(tmp); read(new DataInputViewStreamWrapper(resetStream), false); } }
/** * This read attempts to first identify if the input view contains the special * {@link #VERSIONED_IDENTIFIER} by reading and buffering the first few bytes. * If identified to be versioned, the usual version resolution read path * in {@link VersionedIOReadableWritable#read(DataInputView)} is invoked. * Otherwise, we "reset" the input stream by pushing back the read buffered bytes * into the stream. */ public final void read(InputStream inputStream) throws IOException { byte[] tmp = new byte[VERSIONED_IDENTIFIER.length]; inputStream.read(tmp); if (Arrays.equals(tmp, VERSIONED_IDENTIFIER)) { DataInputView inputView = new DataInputViewStreamWrapper(inputStream); super.read(inputView); read(inputView, true); } else { PushbackInputStream resetStream = new PushbackInputStream(inputStream, VERSIONED_IDENTIFIER.length); resetStream.unread(tmp); read(new DataInputViewStreamWrapper(resetStream), false); } }