use of org.apache.storm.utils.BufferInputStream in project storm by apache.
the class Nimbus method downloadBlobChunk.
@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadBlobChunk(String session) throws AuthorizationException, TException {
try {
BufferInputStream is = blobDownloaders.get(session);
if (is == null) {
throw new RuntimeException("Blob for session " + session + " does not exist (or timed out)");
}
byte[] ret = is.read();
if (ret.length == 0) {
is.close();
blobDownloaders.remove(session);
} else {
blobDownloaders.put(session, is);
}
LOG.debug("Sending {} bytes", ret.length);
return ByteBuffer.wrap(ret);
} catch (Exception e) {
LOG.warn("download blob chunk exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.utils.BufferInputStream in project storm by apache.
the class Nimbus method beginBlobDownload.
@SuppressWarnings("deprecation")
@Override
public BeginDownloadResult beginBlobDownload(String key) throws AuthorizationException, KeyNotFoundException, TException {
try {
InputStreamWithMeta is = blobStore.getBlob(key, getSubject());
String sessionId = Utils.uuid();
BeginDownloadResult ret = new BeginDownloadResult(is.getVersion(), sessionId);
ret.set_data_size(is.getFileLength());
blobDownloaders.put(sessionId, new BufferInputStream(is, (int) conf.getOrDefault(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES, 65536)));
LOG.info("Created download session {} for {}", sessionId, key);
return ret;
} catch (Exception e) {
LOG.warn("begin blob download exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.utils.BufferInputStream in project storm by apache.
the class Nimbus method beginFileDownload.
@SuppressWarnings("deprecation")
@Override
public String beginFileDownload(String file) throws AuthorizationException, TException {
try {
beginFileDownloadCalls.mark();
checkAuthorization(null, null, "fileDownload");
BufferInputStream is = new BufferInputStream(blobStore.getBlob(file, null), Utils.getInt(conf.get(Config.STORM_BLOBSTORE_INPUTSTREAM_BUFFER_SIZE_BYTES), 65536));
String id = Utils.uuid();
downloaders.put(id, is);
return id;
} catch (Exception e) {
LOG.warn("begin file download exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
use of org.apache.storm.utils.BufferInputStream in project storm by apache.
the class Nimbus method downloadChunk.
@SuppressWarnings("deprecation")
@Override
public ByteBuffer downloadChunk(String id) throws AuthorizationException, TException {
try {
downloadChunkCalls.mark();
checkAuthorization(null, null, "fileDownload");
BufferInputStream is = downloaders.get(id);
if (is == null) {
throw new RuntimeException("Could not find input stream for id " + id);
}
byte[] ret = is.read();
if (ret.length == 0) {
is.close();
downloaders.remove(id);
}
return ByteBuffer.wrap(ret);
} catch (Exception e) {
LOG.warn("download chunk exception.", e);
if (e instanceof TException) {
throw (TException) e;
}
throw new RuntimeException(e);
}
}
Aggregations