use of info.ata4.io.buffer.ByteBufferChannel in project disunity by ata4.
the class BundleUtils method byteChannelForEntry.
public static SeekableByteChannel byteChannelForEntry(BundleEntry entry) throws IOException {
SeekableByteChannel chan;
// check if the entry is larger than 128 MiB
long size = entry.size();
if (size > 1 << 27) {
// copy entry to temporary file
Path tmpFile = Files.createTempFile("disunity", null);
Files.copy(entry.inputStream(), tmpFile, REPLACE_EXISTING);
chan = Files.newByteChannel(tmpFile, READ, DELETE_ON_CLOSE);
} else {
// copy entry to memory
ByteBuffer bb = ByteBuffer.allocateDirect((int) size);
IOUtils.copy(entry.inputStream(), new ByteBufferOutputStream(bb));
bb.flip();
chan = new ByteBufferChannel(bb);
}
return chan;
}
Aggregations