/** * Skips <tt>n</tt> bytes in an input stream, throwing IOException if the * number of bytes skipped is different than requested. * @throws IOException If skipping would exceed the available data or skipping did not work. */ private static void trySkip(InputStream in, long n) throws IOException { long skippedBytes = IOUtils.skipFully(in, n); if (skippedBytes != n) { if (skippedBytes < 0) { throw new IOException( "Tried skipping " + n + " bytes, but no bytes were skipped. " + "The end of the stream has been reached or the stream is closed."); } else { throw new IOException( "Tried skipping " + n + " bytes, but only " + skippedBytes + " bytes were skipped. " + "This should never happen with a non-corrupt file."); } } }
long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize); if (streamBlockSize < bigBlockSize) { _stream = new POIFSStream(_filesystem.getMiniStore());
pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3); IOUtils.skipFully(leis, pad);
/** * Skips the current MPEG frame. This method can be called after a valid * MPEG header has been retrieved using {@code nextFrame()}. In this case * the underlying stream is advanced to the end of the associated MPEG * frame or until the EOF is reached. The return value indicates * whether the full frame could be skipped. * * @return <b>true</b> if a frame could be skipped, <b>false</b> otherwise, perhaps EOF? * @throws IOException if an IO error occurs */ public boolean skipFrame() throws IOException { if (currentHeader != null) { long toSkip = currentHeader.getLength() - HEADER_SIZE; long skipped = IOUtils.skipFully(in, toSkip); currentHeader = null; if (skipped < toSkip) { return false; } return true; } return false; }
} else { data = new byte[0]; IOUtils.skipFully(stream, dataLen);
private static void skipToBoundary(int length, InputStream inp) throws IOException { // Data is always padded out to a 4 byte boundary if(length % 4 != 0) { int toSkip = 4 - (length % 4); long skipped = IOUtils.skipFully(inp, toSkip); if (skipped != toSkip) { throw new IOException("tried to skip "+toSkip +" but only skipped:"+skipped); } } } }
@Override public long init(LittleEndianInputStream leis, long recordId, long recordSize) throws IOException { this.recordId = recordId; long skipped = IOUtils.skipFully(leis, recordSize); if (skipped < recordSize) { throw new IOException("End of stream reached before record read"); } return skipped; } }
/** * Skips <tt>n</tt> bytes in an input stream, throwing IOException if the * number of bytes skipped is different than requested. * @throws IOException If skipping would exceed the available data or skipping did not work. */ private static void trySkip(InputStream in, long n) throws IOException { long skippedBytes = IOUtils.skipFully(in, n); if (skippedBytes != n) { if (skippedBytes < 0) { throw new IOException( "Tried skipping " + n + " bytes, but no bytes were skipped. " + "The end of the stream has been reached or the stream is closed."); } else { throw new IOException( "Tried skipping " + n + " bytes, but only " + skippedBytes + " bytes were skipped. " + "This should never happen with a non-corrupt file."); } } }
/** * Skips the current MPEG frame. This method can be called after a valid * MPEG header has been retrieved using {@code nextFrame()}. In this case * the underlying stream is advanced to the end of the associated MPEG * frame or until the EOF is reached. The return value indicates * whether the full frame could be skipped. * * @return <b>true</b> if a frame could be skipped, <b>false</b> otherwise, perhaps EOF? * @throws IOException if an IO error occurs */ public boolean skipFrame() throws IOException { if (currentHeader != null) { long toSkip = currentHeader.getLength() - HEADER_SIZE; long skipped = IOUtils.skipFully(in, toSkip); currentHeader = null; if (skipped < toSkip) { return false; } return true; } return false; }
} else { data = new byte[0]; IOUtils.skipFully(stream, dataLen);
private byte[] readToByteArray(LittleEndianInputStream leis, long dataSize, long recordSize) throws IOException { if (recordSize == 0) { return new byte[0]; } byte[] arr = IOUtils.safelyAllocate(dataSize, MAX_RECORD_LENGTH); long read = IOUtils.readFully(leis, arr); if (read != dataSize) { throw new RecordFormatException("InputStream ended before full record could be read"); } long toSkip = recordSize-dataSize; long skipped = IOUtils.skipFully(leis, recordSize-dataSize); if (toSkip != skipped) { throw new RecordFormatException("InputStream ended before full record could be read"); } return arr; }
long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize); if (streamBlockSize < bigBlockSize) { _stream = new POIFSStream(_filesystem.getMiniStore());
private byte[] readToByteArray(byte[] initialBytes, LittleEndianInputStream leis, long remainingDataSize, long remainingRecordSize) throws IOException { if (remainingDataSize > Integer.MAX_VALUE) { throw new RecordFormatException("Data size can't be > Integer.MAX_VALUE"); } if (remainingRecordSize > Integer.MAX_VALUE) { throw new RecordFormatException("Record size can't be > Integer.MAX_VALUE"); } if (remainingRecordSize == 0) { return new byte[0]; } int dataSize = (int)remainingDataSize; int recordSize = (int)remainingRecordSize; byte[] arr = IOUtils.safelyAllocate(dataSize+initialBytes.length, MAX_RECORD_LENGTH); System.arraycopy(initialBytes,0,arr, 0, initialBytes.length); long read = IOUtils.readFully(leis, arr, initialBytes.length, dataSize); if (read != dataSize) { throw new RecordFormatException("InputStream ended before full record could be read"); } long toSkip = recordSize-dataSize; long skipped = IOUtils.skipFully(leis, toSkip); if (toSkip != skipped) { throw new RecordFormatException("InputStream ended before full record could be read"); } return arr; }
throw new RecordFormatException("read too many bytes. record size: "+recordSize + "; comsumed size: "+consumedSize); } else if(remainingSize > 0) { long skipped = IOUtils.skipFully(leis, remainingSize); if (skipped != (long)remainingSize) { throw new RecordFormatException("Tried to skip "+remainingSize + " but skipped: "+skipped);
pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3); IOUtils.skipFully(leis, pad);