use of java.nio.channels.SeekableByteChannel in project Symphony by Vazkii.
the class Mp3File method saveMpegFrames.
private void saveMpegFrames(SeekableByteChannel saveFile) throws IOException {
int filePos = xingOffset;
if (filePos < 0)
filePos = startOffset;
if (filePos < 0)
return;
if (endOffset < filePos)
return;
SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, StandardOpenOption.READ);
ByteBuffer byteBuffer = ByteBuffer.allocate(bufferLength);
try {
seekableByteChannel.position(filePos);
while (true) {
byteBuffer.clear();
int bytesRead = seekableByteChannel.read(byteBuffer);
byteBuffer.rewind();
if (filePos + bytesRead <= endOffset) {
byteBuffer.limit(bytesRead);
saveFile.write(byteBuffer);
filePos += bytesRead;
} else {
byteBuffer.limit(endOffset - filePos + 1);
saveFile.write(byteBuffer);
break;
}
}
} finally {
seekableByteChannel.close();
}
}
use of java.nio.channels.SeekableByteChannel in project Symphony by Vazkii.
the class Mp3File method init.
private void init(int bufferLength, boolean scanFile) throws IOException, UnsupportedTagException, InvalidDataException {
if (bufferLength < MINIMUM_BUFFER_LENGTH + 1)
throw new IllegalArgumentException("Buffer too small");
this.bufferLength = bufferLength;
this.scanFile = scanFile;
try (SeekableByteChannel seekableByteChannel = Files.newByteChannel(path, StandardOpenOption.READ)) {
initId3v1Tag(seekableByteChannel);
scanFile(seekableByteChannel);
if (startOffset < 0) {
throw new InvalidDataException("No mpegs frames found");
}
initId3v2Tag(seekableByteChannel);
if (scanFile) {
initCustomTag(seekableByteChannel);
}
}
}
use of java.nio.channels.SeekableByteChannel in project redisson by redisson.
the class RedissonBinaryStreamTest method testChannelPosition.
@Test
public void testChannelPosition() throws IOException {
RBinaryStream stream = redisson.getBinaryStream("test");
SeekableByteChannel c = stream.getChannel();
c.write(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7 }));
c.position(3);
ByteBuffer b = ByteBuffer.allocate(3);
c.read(b);
assertThat(c.position()).isEqualTo(6);
byte[] bb = new byte[3];
b.flip();
b.get(bb);
assertThat(bb).isEqualTo(new byte[] { 4, 5, 6 });
}
use of java.nio.channels.SeekableByteChannel in project redisson by redisson.
the class RedissonBinaryStreamTest method testChannelTruncate.
@Test
public void testChannelTruncate() throws IOException {
RBinaryStream stream = redisson.getBinaryStream("test");
SeekableByteChannel c = stream.getChannel();
c.write(ByteBuffer.wrap(new byte[] { 1, 2, 3, 4, 5, 6, 7 }));
assertThat(c.size()).isEqualTo(7);
c.truncate(3);
c.position(0);
c.truncate(10);
ByteBuffer b = ByteBuffer.allocate(3);
c.read(b);
byte[] bb = new byte[3];
b.flip();
b.get(bb);
assertThat(c.size()).isEqualTo(3);
assertThat(bb).isEqualTo(new byte[] { 1, 2, 3 });
}
use of java.nio.channels.SeekableByteChannel in project dex2jar by pxb1988.
the class ExtractOdexFromCoredumpCmd method doCommandLine.
@Override
protected void doCommandLine() throws Exception {
if (remainingArgs.length < 1) {
throw new HelpException("<core.xxxx> is required.");
}
Path core = new File(remainingArgs[0]).toPath();
try (SeekableByteChannel channel = FileChannel.open(core, StandardOpenOption.READ)) {
List<Long> possibleOdexs = findPossibleOdexLocation(channel);
extractDex(channel, possibleOdexs, core.getFileName().toString());
}
}
Aggregations