public void create(ServiceDescription sd) throws ServantException { super.create(sd); Properties p = sd.getProperties(); int bufferSize = PropertiesConstants.getInt(p, "bufferSize", 10240, true); buffer = new byte[bufferSize]; domain = PropertiesConstants.getString(p, "blob.domain", domain); blobManager = BlobTool.getBlobManager(domain); if (blobManager == null) { throw new ServantException( "core.blob_not_found", "Can not find a blob manager named: " + domain); } }
public int actionProcess(Context ctx) throws Exception { ctx.asMessage(BlobMessage.class); String fileId = getArgument("fileId", ctx); String domain = getArgument("domain", "default", ctx); BlobManager manager = BlobTool.getBlobManager(domain); if (manager == null) { throw new ServantException( "core.blob_not_found", "Can not find a blob manager named " + domain); } BlobReader reader = manager.getFile(fileId); if (reader == null) { throw new ServantException("core.blob_not_found", "Can not find a blob file named " + fileId); } BlobInfo info = reader.getBlobInfo(); ctx.setResponseContentType(info.contentType()); InputStream in = reader.getInputStream(0); OutputStream out = ctx.getOutputStream(); try { int size = 0; while ((size = in.read(buffer)) != -1) { out.write(buffer, 0, size); } } finally { IOTools.close(in); } return 0; }