本文整理了Java中org.apache.poi.util.IOUtils.skipFully()
方法的一些代码示例,展示了IOUtils.skipFully()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.skipFully()
方法的具体详情如下:
包路径:org.apache.poi.util.IOUtils
类名称:IOUtils
方法名:skipFully
[英]Skips bytes from an input byte stream. This implementation guarantees that it will read as many bytes as possible before giving up; this may not always be the case for skip() implementations in subclasses of InputStream.
Note that the implementation uses InputStream#read(byte[],int,int) rather than delegating to InputStream#skip(long). This means that the method may be considerably less efficient than using the actual skip implementation, this is done to guarantee that the correct number of bytes are skipped.
This mimics POI's #readFully(InputStream,byte[]). If the end of file is reached before any bytes are read, returns -1. If the end of the file is reached after some bytes are read, returns the number of bytes read. If the end of the file isn't reached before len bytes have been read, will return len bytes.
Copied nearly verbatim from commons-io 41a3e9c
[中]从输入字节流跳过字节。这种实现保证了它在放弃之前将读取尽可能多的字节;InputStream子类中的skip()实现可能并不总是如此。
注意,该实现使用InputStream#read(byte[],int,int)而不是委托给InputStream#skip(long)。这意味着该方法的效率可能远低于使用实际的跳过实现,这样做是为了确保跳过正确的字节数。
这很容易模仿POI(InputStream,字节[])。如果在读取任何字节之前到达文件末尾,则返回-1。如果在读取某些字节后到达文件末尾,则返回读取的字节数。如果在读取len字节之前未到达文件结尾,将返回len字节。
几乎一字不差地从commons io 41a3e9c复制
代码示例来源:origin: org.apache.poi/poi
/**
* 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.");
}
}
}
代码示例来源:origin: org.apache.poi/poi
long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize);
if (streamBlockSize < bigBlockSize) {
_stream = new POIFSStream(_filesystem.getMiniStore());
代码示例来源:origin: org.apache.poi/poi
pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3);
IOUtils.skipFully(leis, pad);
代码示例来源:origin: apache/tika
/**
* 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;
}
代码示例来源:origin: apache/tika
} else {
data = new byte[0];
IOUtils.skipFully(stream, dataLen);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
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);
}
}
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
@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;
}
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
/**
* 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.");
}
}
}
代码示例来源:origin: org.apache.tika/tika-parsers
/**
* 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;
}
代码示例来源:origin: org.apache.tika/tika-parsers
} else {
data = new byte[0];
IOUtils.skipFully(stream, dataLen);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
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;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
long streamBlockSize = IOUtils.skipFully(bis, bigBlockSize);
if (streamBlockSize < bigBlockSize) {
_stream = new POIFSStream(_filesystem.getMiniStore());
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
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;
}
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
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);
代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.poi
pad = 2+((4 - ((nrBytes+2) & 0x3)) & 0x3);
IOUtils.skipFully(leis, pad);
内容来源于网络,如有侵权,请联系作者删除!