use of java.nio.channels.WritableByteChannel in project jstorm by alibaba.
the class Utils method downloadFromMaster.
public static void downloadFromMaster(Map conf, String file, String localFile) throws IOException, TException {
WritableByteChannel out = null;
NimbusClient client = null;
try {
client = NimbusClient.getConfiguredClient(conf, 10 * 1000);
String id = client.getClient().beginFileDownload(file);
out = Channels.newChannel(new FileOutputStream(localFile));
while (true) {
ByteBuffer chunk = client.getClient().downloadChunk(id);
int written = out.write(chunk);
if (written == 0) {
client.getClient().finishFileDownload(id);
break;
}
}
} finally {
if (out != null)
out.close();
if (client != null)
client.close();
}
}
use of java.nio.channels.WritableByteChannel in project jstorm by alibaba.
the class ServiceHandler method uploadChunk.
/**
* uploading topology jar data
*/
@Override
public void uploadChunk(String location, ByteBuffer chunk) throws TException {
TimeCacheMap<Object, Object> uploaders = data.getUploaders();
Object obj = uploaders.get(location);
if (obj == null) {
throw new TException("File for that location does not exist (or timed out) " + location);
}
try {
if (obj instanceof WritableByteChannel) {
WritableByteChannel channel = (WritableByteChannel) obj;
channel.write(chunk);
uploaders.put(location, channel);
} else {
throw new TException("Object isn't WritableByteChannel for " + location);
}
} catch (IOException e) {
String errMsg = " WritableByteChannel write filed when uploadChunk " + location;
LOG.error(errMsg);
throw new TException(e);
}
}
use of java.nio.channels.WritableByteChannel in project neo4j by neo4j.
the class PageCacheTest method writableByteChannelMustBeOpenUntilClosed.
@Test(timeout = SHORT_TIMEOUT_MILLIS)
public void writableByteChannelMustBeOpenUntilClosed() throws Exception {
configureStandardPageCache();
try (PagedFile pf = pageCache.map(file("a"), filePageSize)) {
WritableByteChannel channel;
try (WritableByteChannel ch = pf.openWritableByteChannel()) {
assertTrue(ch.isOpen());
channel = ch;
}
assertFalse(channel.isOpen());
}
}
use of java.nio.channels.WritableByteChannel in project storm by nathanmarz.
the class Utils method downloadFromMaster.
public static void downloadFromMaster(Map conf, String file, String localFile) throws IOException, TException {
NimbusClient client = NimbusClient.getConfiguredClient(conf);
String id = client.getClient().beginFileDownload(file);
WritableByteChannel out = Channels.newChannel(new FileOutputStream(localFile));
while (true) {
ByteBuffer chunk = client.getClient().downloadChunk(id);
int written = out.write(chunk);
if (written == 0)
break;
}
out.close();
}
use of java.nio.channels.WritableByteChannel in project dbeaver by serge-rider.
the class IOUtils method fastCopy.
public static void fastCopy(final InputStream src, final OutputStream dest, int bufferSize) throws IOException {
final ReadableByteChannel inputChannel = Channels.newChannel(src);
final WritableByteChannel outputChannel = Channels.newChannel(dest);
fastCopy(inputChannel, outputChannel, bufferSize);
}
Aggregations