use of java.nio.channels.SeekableByteChannel in project jetty.project by eclipse.
the class FrameCaptureExtension method saveFrame.
private void saveFrame(Frame frame, boolean outgoing) {
if (outputDir == null || generator == null) {
return;
}
@SuppressWarnings("resource") SeekableByteChannel channel = (outgoing) ? outgoingChannel : incomingChannel;
if (channel == null) {
return;
}
ByteBuffer buf = getBufferPool().acquire(BUFSIZE, false);
try {
WebSocketFrame f = WebSocketFrame.copy(frame);
f.setMasked(false);
generator.generateHeaderBytes(f, buf);
channel.write(buf);
if (frame.hasPayload()) {
channel.write(frame.getPayload().slice());
}
if (LOG.isDebugEnabled())
LOG.debug("Saved {} frame #{}", (outgoing) ? "outgoing" : "incoming", (outgoing) ? outgoingCount.incrementAndGet() : incomingCount.incrementAndGet());
} catch (IOException e) {
LOG.warn("Unable to save frame: " + frame, e);
} finally {
getBufferPool().release(buf);
}
}
use of java.nio.channels.SeekableByteChannel in project java-chassis by ServiceComb.
the class FortifyUtils method writeFile.
public static void writeFile(String file, byte[] content) throws IOException {
Set<OpenOption> options = new HashSet<OpenOption>();
//options.add(StandardOpenOption.CREATE_NEW);
//options.add(StandardOpenOption.APPEND);
//覆写文件
options.add(StandardOpenOption.CREATE);
options.add(StandardOpenOption.WRITE);
SeekableByteChannel sbc = null;
try {
FileAttribute<?> fa = getDefaultFileAttributes(file);
ByteBuffer buffer = ByteBuffer.wrap(content);
sbc = Files.newByteChannel(new File(file).toPath(), options, fa);
// write data
sbc.write(buffer);
} finally {
IOUtils.closeQuietly(sbc);
}
}
use of java.nio.channels.SeekableByteChannel in project lucene-solr by apache.
the class TestLeakFS method testLeakByteChannel.
/** Test leaks via Files.newByteChannel */
public void testLeakByteChannel() throws IOException {
Path dir = wrap(createTempDir());
OutputStream file = Files.newOutputStream(dir.resolve("stillopen"));
file.write(5);
file.close();
SeekableByteChannel leak = Files.newByteChannel(dir.resolve("stillopen"));
try {
dir.getFileSystem().close();
fail("should have gotten exception");
} catch (Exception e) {
assertTrue(e.getMessage().contains("file handle leaks"));
}
leak.close();
}
use of java.nio.channels.SeekableByteChannel in project lucene-solr by apache.
the class TestVerboseFS method testByteChannel.
/** Test newByteChannel */
public void testByteChannel() throws IOException {
InfoStreamListener stream = new InfoStreamListener("newByteChannel");
Path dir = wrap(createTempDir(), stream);
SeekableByteChannel channel = Files.newByteChannel(dir.resolve("foobar"), StandardOpenOption.CREATE_NEW, StandardOpenOption.READ, StandardOpenOption.WRITE);
assertTrue(stream.sawMessage());
channel.close();
try {
Files.newByteChannel(dir.resolve("foobar"), StandardOpenOption.CREATE_NEW, StandardOpenOption.READ, StandardOpenOption.WRITE);
fail("didn't get expected exception");
} catch (IOException expected) {
}
}
use of java.nio.channels.SeekableByteChannel in project beam by apache.
the class GcsUtilTest method testGCSChannelCloseIdempotent.
@Test
public void testGCSChannelCloseIdempotent() throws IOException {
SeekableByteChannel channel = new GoogleCloudStorageReadChannel(null, "dummybucket", "dummyobject", null, new ClientRequestHelper<StorageObject>());
channel.close();
channel.close();
}
Aggregations