use of java.nio.channels.WritableByteChannel in project storm by apache.
the class Nimbus method uploadChunk.
@SuppressWarnings("deprecation")
@Override
public void uploadChunk(String location, ByteBuffer chunk) throws AuthorizationException, TException {
try {
uploadChunkCalls.mark();
checkAuthorization(null, null, "fileUpload");
WritableByteChannel channel = uploaders.get(location);
if (channel == null) {
throw new RuntimeException("File for that location does not exist (or timed out)");
}
channel.write(chunk);
uploaders.put(location, channel);
} catch (Exception e) {
LOG.warn("uploadChunk exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of java.nio.channels.WritableByteChannel in project storm by apache.
the class Nimbus method finishFileUpload.
@SuppressWarnings("deprecation")
@Override
public void finishFileUpload(String location) throws AuthorizationException, TException {
try {
finishFileUploadCalls.mark();
checkAuthorization(null, null, "fileUpload");
WritableByteChannel channel = uploaders.get(location);
if (channel == null) {
throw new RuntimeException("File for that location does not exist (or timed out)");
}
channel.close();
LOG.info("Finished uploading file from client: {}", location);
uploaders.remove(location);
} catch (Exception e) {
LOG.warn("finish file upload exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of java.nio.channels.WritableByteChannel in project LuaViewSDK by alibaba.
the class ChannelTools method fastCopy.
/**
* fast copy
*
* @param inputStream
* @param outputStream
* @throws IOException
*/
public static void fastCopy(InputStream inputStream, OutputStream outputStream) throws IOException {
final ReadableByteChannel input = Channels.newChannel(inputStream);
final WritableByteChannel output = Channels.newChannel(outputStream);
fastCopy(input, output);
}
use of java.nio.channels.WritableByteChannel in project neo4j by neo4j.
the class StreamToDisk method write.
@Override
public void write(String destination, int requiredAlignment, byte[] data) throws IOException {
File fileName = new File(storeDir, destination);
fs.mkdirs(fileName.getParentFile());
fileCopyMonitor.copyFile(fileName);
if (StoreType.shouldBeManagedByPageCache(destination)) {
WritableByteChannel channel = channels.get(destination);
if (channel == null) {
int filePageSize = pageCache.pageSize() - pageCache.pageSize() % requiredAlignment;
PagedFile pagedFile = pageCache.map(fileName, filePageSize, StandardOpenOption.CREATE);
channel = pagedFile.openWritableByteChannel();
pagedFiles.put(destination, pagedFile);
channels.put(destination, channel);
}
ByteBuffer buffer = ByteBuffer.wrap(data);
while (buffer.hasRemaining()) {
channel.write(buffer);
}
} else {
try (OutputStream outputStream = fs.openAsOutputStream(fileName, true)) {
outputStream.write(data);
}
}
}
use of java.nio.channels.WritableByteChannel in project neo4j by neo4j.
the class PageCacheTest method writingToClosedWritableByteChannelMustThrow.
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void writingToClosedWritableByteChannelMustThrow() throws Exception {
File file = file("a");
configureStandardPageCache();
try (PagedFile pf = pageCache.map(file, filePageSize)) {
WritableByteChannel channel = pf.openWritableByteChannel();
channel.close();
expectedException.expect(ClosedChannelException.class);
channel.write(ByteBuffer.allocate(recordSize));
fail("That read should have thrown");
}
}
Aggregations