@Override public long getPos() throws IOException { return fsDataInputStream.getPos(); }
@Override public long getPos() throws IOException { return ((FSDataInputStream) in).getPos(); } }
/** Return the current byte position in the input file. */ public synchronized long getPosition() throws IOException { return in.getPos(); }
@Override public long getPosition() throws IOException { return inputStream.getPos(); }
@Override public synchronized int available() throws IOException { long remaining = end - underLyingStream.getPos(); if (remaining > Integer.MAX_VALUE) { return Integer.MAX_VALUE; } return (int) remaining; }
@Override public long tell() throws IOException { return this.stream.getPos(); }
/** Return the current byte position in the input file. */ public synchronized long getPosition() throws IOException { return in.getPos(); }
@Override public long tell() throws IOException { return stream.getPos(); }
/** Return the current byte position in the input file. */ public synchronized long getPosition() throws IOException { return in.getPos(); }
@Override public long tell() throws IOException { return stream.getPos(); }
public void open() throws IOException { if (stream == null) { stream = fs.open(logFile); } if (header == null) { header = ProcedureWALFormat.readHeader(stream); startPos = stream.getPos(); } else { stream.seek(startPos); } }
/** * Read and return the next record length, potentially skipping over a sync * block. * * @return the length of the next record or -1 if there is no next record * @throws IOException */ private synchronized int readRecordLength() throws IOException { if (in.getPos() >= end) { return -1; } int length = in.readInt(); if (sync != null && length == SYNC_ESCAPE) { // process // a // sync entry lastSeenSyncPos = in.getPos() - 4; // minus SYNC_ESCAPE's length in.readFully(syncCheck); // read syncCheck if (!Arrays.equals(sync, syncCheck)) { throw new IOException("File is corrupt!"); } syncSeen = true; if (in.getPos() >= end) { return -1; } length = in.readInt(); // re-read length } else { syncSeen = false; } return length; }
/** {@inheritDoc} */ @Override public synchronized long getPos() throws IOException { readStart(); try { return is.getPos(); } finally { readEnd(); } }
/** This constructor is there primarily to serve the sort routine that * generates a single output file with an associated index file */ public SegmentContainer(Path inName, Path indexIn) throws IOException { //get the segments from indexIn FSDataInputStream fsIndexIn = fs.open(indexIn); long end = fs.getFileStatus(indexIn).getLen(); while (fsIndexIn.getPos() < end) { long segmentOffset = WritableUtils.readVLong(fsIndexIn); long segmentLength = WritableUtils.readVLong(fsIndexIn); Path segmentName = inName; segments.add(new LinkedSegmentsDescriptor(segmentOffset, segmentLength, segmentName, this)); } fsIndexIn.close(); fs.delete(indexIn, true); numSegmentsContained = segments.size(); this.inName = inName; }
private int nextKeyValueTolerateCorruptions() throws IOException { long currentOffset = in.getPos(); int ret; try { ret = nextKeyBuffer(); this.currentValueBuffer(); } catch (IOException ioe) { // A BlockMissingException indicates a temporary error, // not a corruption. Re-throw this exception. String msg = ioe.getMessage(); if (msg != null && msg.startsWith(BLOCK_MISSING_MESSAGE)) { LOG.warn("Re-throwing block-missing exception" + ioe); throw ioe; } // We have an IOException other than a BlockMissingException. LOG.warn("Ignoring IOException in file " + file + " after offset " + currentOffset, ioe); ret = -1; } catch (Throwable t) { // We got an exception that is not IOException // (typically OOM, IndexOutOfBounds, InternalError). // This is most likely a corruption. LOG.warn("Ignoring unknown error in " + file + " after offset " + currentOffset, t); ret = -1; } return ret; }
private long dumpFromOffset(PathData item, long offset) throws IOException { long fileSize = item.refreshStatus().getLen(); if (offset > fileSize) return fileSize; // treat a negative offset as relative to end of the file, floor of 0 if (offset < 0) { offset = Math.max(fileSize + offset, 0); } FSDataInputStream in = item.fs.open(item.path); try { in.seek(offset); // use conf so the system configured io block size is used IOUtils.copyBytes(in, System.out, getConf(), false); offset = in.getPos(); } finally { in.close(); } return offset; } }
in = fs.open(path, bufferSize); if (pos != 0) in.seek(pos); assert(in.getPos() == pos) : "Link unable to seek to the right position=" + pos; if (LOG.isTraceEnabled()) { if (currentPath == null) {
private void seekAndAssert(long seekPos) throws IOException { Assert.assertEquals(verifyInputStream.getPos(), testInputStream.getPos()); long delta = seekPos - testInputStream.getPos(); testInputStream.seek(seekPos); if (delta > 0L && delta <= HadoopDataInputStream.MIN_SKIP_BYTES) { verify(verifyInputStream, atLeastOnce()).skip(anyLong()); verify(verifyInputStream, never()).seek(anyLong()); } else if (delta != 0L) { verify(verifyInputStream, atLeastOnce()).seek(seekPos); verify(verifyInputStream, never()).skip(anyLong()); } else { verify(verifyInputStream, never()).seek(anyLong()); verify(verifyInputStream, never()).skip(anyLong()); } Assert.assertEquals(seekPos, verifyInputStream.getPos()); reset(verifyInputStream); }
@Override public int read(byte[] b, int off, int len) throws IOException { int n; try { n = in.read(b, off, len); } catch (FileNotFoundException e) { n = tryOpen().read(b, off, len); } catch (NullPointerException e) { // HDFS 1.x - DFSInputStream.getBlockAt() n = tryOpen().read(b, off, len); } catch (AssertionError e) { // assert in HDFS 1.x - DFSInputStream.getBlockAt() n = tryOpen().read(b, off, len); } if (n > 0) pos += n; assert(in.getPos() == pos); return n; }
public static ProcedureWALTrailer readTrailer(FSDataInputStream stream, long startPos, long size) throws IOException { // Beginning of the Trailer Jump. 17 = 1 byte version + 8 byte magic + 8 byte offset long trailerPos = size - 17; if (trailerPos < startPos) { throw new InvalidWALDataException("Missing trailer: size=" + size + " startPos=" + startPos); } stream.seek(trailerPos); int version = stream.read(); if (version != TRAILER_VERSION) { throw new InvalidWALDataException("Invalid Trailer version. got " + version + " expected " + TRAILER_VERSION); } long magic = StreamUtils.readLong(stream); if (magic != TRAILER_MAGIC) { throw new InvalidWALDataException("Invalid Trailer magic. got " + magic + " expected " + TRAILER_MAGIC); } long trailerOffset = StreamUtils.readLong(stream); stream.seek(trailerOffset); ProcedureWALEntry entry = readEntry(stream); if (entry.getType() != ProcedureWALEntry.Type.PROCEDURE_WAL_EOF) { throw new InvalidWALDataException("Invalid Trailer begin"); } ProcedureWALTrailer trailer = ProcedureWALTrailer.newBuilder() .setVersion(version) .setTrackerPos(stream.getPos()) .build(); return trailer; }