本文整理了Java中org.apache.commons.compress.utils.IOUtils.readFully()
方法的一些代码示例,展示了IOUtils.readFully()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.readFully()
方法的具体详情如下:
包路径:org.apache.commons.compress.utils.IOUtils
类名称:IOUtils
方法名:readFully
[英]Reads as much from input as possible to fill the given array.
This method may invoke read repeatedly to fill the array and only read less bytes than the length of the array if the end of the stream has been reached.
[中]从输入中读取尽可能多的数据以填充给定数组。
此方法可以重复调用read来填充数组,如果到达流的末尾,则只读取小于数组长度的字节。
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Reads as much from input as possible to fill the given array.
*
* <p>This method may invoke read repeatedly to fill the array and
* only read less bytes than the length of the array if the end of
* the stream has been reached.</p>
*
* @param input stream to read from
* @param b buffer to fill
* @return the number of bytes actually read
* @throws IOException on error
*/
public static int readFully(final InputStream input, final byte[] b) throws IOException {
return readFully(input, b, 0, b.length);
}
代码示例来源:origin: org.apache.commons/commons-compress
private void readFully(ByteBuffer buf) throws IOException {
buf.rewind();
IOUtils.readFully(channel, buf);
buf.flip();
}
代码示例来源:origin: org.apache.commons/commons-compress
private final int readFully(final byte[] b, final int off, final int len)
throws IOException {
final int count = IOUtils.readFully(in, b, off, len);
count(count);
if (count < len) {
throw new EOFException();
}
return count;
}
代码示例来源:origin: org.apache.commons/commons-compress
private void readFully(final byte[] b, final int off) throws IOException {
final int len = b.length - off;
final int count = IOUtils.readFully(in, b, off, len);
count(count);
if (count < len) {
throw new EOFException();
}
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Checks whether the archive starts with a LFH. If it doesn't,
* it may be an empty archive.
*/
private boolean startsWithLocalFileHeader() throws IOException {
archive.position(0);
wordBbuf.rewind();
IOUtils.readFully(archive, wordBbuf);
return Arrays.equals(wordBuf, ZipArchiveOutputStream.LFH_SIG);
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Read buffer
*/
private void readFully(final byte[] b, final int off, final int len)
throws IOException {
final int count = IOUtils.readFully(in, b, off, len);
if (count < len) {
throw new ShortFileException();
}
}
代码示例来源:origin: org.apache.commons/commons-compress
private void tryToReadLiteral(int bytesToRead) throws IOException {
// min of "what is still inside the literal", "what does the user want" and "how muc can fit into the buffer"
final int reallyTryToRead = Math.min((int) Math.min(bytesToRead, bytesRemaining),
buf.length - writeIndex);
final int bytesRead = reallyTryToRead > 0
? IOUtils.readFully(in, buf, writeIndex, reallyTryToRead)
: 0 /* happens for bytesRemaining == 0 */;
count(bytesRead);
if (reallyTryToRead != bytesRead) {
throw new IOException("Premature end of stream reading literal");
}
writeIndex += reallyTryToRead;
bytesRemaining -= reallyTryToRead;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Read a record from the input stream and return the data.
*
* @return The record data or null if EOF has been hit.
* @throws IOException on error
*/
protected byte[] readRecord() throws IOException {
final byte[] record = new byte[recordSize];
final int readNow = IOUtils.readFully(is, record);
count(readNow);
if (readNow != recordSize) {
return null;
}
return record;
}
代码示例来源:origin: org.apache.commons/commons-compress
final int read = readFully(input, SKIP_BUF, 0,
(int) Math.min(numToSkip, SKIP_BUF_SIZE));
if (read < 1) {
代码示例来源:origin: org.apache.commons/commons-compress
private long readCrc() throws IOException {
final byte[] b = new byte[4];
final int read = IOUtils.readFully(in, b);
count(read);
if (read != 4) {
throw new IOException("premature end of stream");
}
return ByteUtils.fromLittleEndian(b);
}
代码示例来源:origin: org.apache.commons/commons-compress
private void readStreamIdentifier() throws IOException {
final byte[] b = new byte[10];
final int read = IOUtils.readFully(in, b);
count(read);
if (10 != read || !matches(b, 10)) {
throw new IOException("Not a framed Snappy stream");
}
}
代码示例来源:origin: org.apache.commons/commons-compress
private void verifyChecksum(XXHash32 hash, String kind) throws IOException {
byte[] checksum = new byte[4];
int read = IOUtils.readFully(in, checksum);
count(read);
if (4 != read) {
throw new IOException("Premature end of stream while reading " + kind + " checksum");
}
long expectedHash = hash.getValue();
if (expectedHash != ByteUtils.fromLittleEndian(checksum)) {
throw new IOException(kind + " checksum mismatch.");
}
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Reads the real name from the current stream assuming the very
* first bytes to be read are the real file name.
*
* @see #isBSDLongName
*
* @since 1.3
*/
private String getBSDLongName(final String bsdLongName) throws IOException {
final int nameLen =
Integer.parseInt(bsdLongName.substring(BSD_LONGNAME_PREFIX_LEN));
final byte[] name = new byte[nameLen];
final int read = IOUtils.readFully(input, name);
trackReadBytes(read);
if (read != nameLen) {
throw new EOFException();
}
return ArchiveUtils.toAsciiString(name);
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Parses the "End of central dir record" and positions
* the stream at the first central directory record.
*
* Expects stream to be positioned at the beginning of the
* "End of central dir record".
*/
private void positionAtCentralDirectory32()
throws IOException {
skipBytes(CFD_LOCATOR_OFFSET);
wordBbuf.rewind();
IOUtils.readFully(archive, wordBbuf);
archive.position(ZipLong.getValue(wordBuf));
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Reads the GNU archive String Table.
*
* @see #isGNUStringTable
*/
private ArArchiveEntry readGNUStringTable(final byte[] length, final int offset, final int len) throws IOException {
final int bufflen = asInt(length, offset, len); // Assume length will fit in an int
namebuffer = new byte[bufflen];
final int read = IOUtils.readFully(input, namebuffer, 0, bufflen);
trackReadBytes(read);
if (read != bufflen){
throw new IOException("Failed to read complete // record: expected="
+ bufflen + " read=" + read);
}
return new ArArchiveEntry(GNU_STRING_TABLE_NAME, bufflen);
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Parses the "Zip64 end of central directory locator",
* finds the "Zip64 end of central directory record" using the
* parsed information, parses that and positions the stream at the
* first central directory record.
*
* Expects stream to be positioned right behind the "Zip64
* end of central directory locator"'s signature.
*/
private void positionAtCentralDirectory64()
throws IOException {
skipBytes(ZIP64_EOCDL_LOCATOR_OFFSET
- WORD /* signature has already been read */);
dwordBbuf.rewind();
IOUtils.readFully(archive, dwordBbuf);
archive.position(ZipEightByteInteger.getLongValue(dwordBuf));
wordBbuf.rewind();
IOUtils.readFully(archive, wordBbuf);
if (!Arrays.equals(wordBuf, ZipArchiveOutputStream.ZIP64_EOCD_SIG)) {
throw new ZipException("archive's ZIP64 end of central "
+ "directory locator is corrupt.");
}
skipBytes(ZIP64_EOCD_CFD_LOCATOR_OFFSET
- WORD /* signature has already been read */);
dwordBbuf.rewind();
IOUtils.readFully(archive, dwordBbuf);
archive.position(ZipEightByteInteger.getLongValue(dwordBuf));
}
代码示例来源:origin: org.apache.commons/commons-compress
IOUtils.readFully(archive, wordBbuf);
long sig = ZipLong.getValue(wordBuf);
readCentralDirectoryEntry(noUTF8Flag);
wordBbuf.rewind();
IOUtils.readFully(archive, wordBbuf);
sig = ZipLong.getValue(wordBuf);
代码示例来源:origin: org.apache.commons/commons-compress
private boolean readSignature(boolean firstFrame) throws IOException {
String garbageMessage = firstFrame ? "Not a LZ4 frame stream" : "LZ4 frame stream followed by garbage";
final byte[] b = new byte[4];
int read = IOUtils.readFully(in, b);
count(read);
if (0 == read && !firstFrame) {
// good LZ4 frame and nothing after it
endReached = true;
return false;
}
if (4 != read) {
throw new IOException(garbageMessage);
}
read = skipSkippableFrame(b);
if (0 == read && !firstFrame) {
// good LZ4 frame with only some skippable frames after it
endReached = true;
return false;
}
if (4 != read || !matches(b, 4)) {
throw new IOException(garbageMessage);
}
return true;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Skips over the contents of a skippable frame as well as
* skippable frames following it.
*
* <p>It then tries to read four more bytes which are supposed to
* hold an LZ4 signature and returns the number of bytes read
* while storing the bytes in the given array.</p>
*/
private int skipSkippableFrame(byte[] b) throws IOException {
int read = 4;
while (read == 4 && isSkippableFrameSignature(b)) {
long len = ByteUtils.fromLittleEndian(supplier, 4);
long skipped = IOUtils.skip(in, len);
count(skipped);
if (len != skipped) {
throw new IOException("Premature end of stream while skipping frame");
}
read = IOUtils.readFully(in, b);
count(read);
}
return read;
}
代码示例来源:origin: org.apache.commons/commons-compress
/**
* Searches for either the "Zip64 end of central directory
* locator" or the "End of central dir record", parses
* it and positions the stream at the first central directory
* record.
*/
private void positionAtCentralDirectory()
throws IOException {
positionAtEndOfCentralDirectoryRecord();
boolean found = false;
final boolean searchedForZip64EOCD =
archive.position() > ZIP64_EOCDL_LENGTH;
if (searchedForZip64EOCD) {
archive.position(archive.position() - ZIP64_EOCDL_LENGTH);
wordBbuf.rewind();
IOUtils.readFully(archive, wordBbuf);
found = Arrays.equals(ZipArchiveOutputStream.ZIP64_EOCD_LOC_SIG,
wordBuf);
}
if (!found) {
// not a ZIP64 archive
if (searchedForZip64EOCD) {
skipBytes(ZIP64_EOCDL_LENGTH - WORD);
}
positionAtCentralDirectory32();
} else {
positionAtCentralDirectory64();
}
}
内容来源于网络,如有侵权,请联系作者删除!