use of com.sun.jersey.core.header.ContentDisposition in project onebusaway-application-modules by camsys.
the class LocalBundleDeployerServiceImpl method getBundleFile.
@Override
public Response getBundleFile(String bundleId, String relativeFilename) {
_log.info("starting getBundleFile for relative filename " + relativeFilename + " in bundle " + bundleId);
boolean requestIsForValidBundleFile = bundleProvider.checkIsValidBundleFile(bundleId, relativeFilename);
if (!requestIsForValidBundleFile) {
throw new WebApplicationException(new IllegalArgumentException(relativeFilename + " is not listed in bundle metadata."), Response.Status.BAD_REQUEST);
}
final File requestedFile;
try {
requestedFile = bundleProvider.getBundleFile(bundleId, relativeFilename);
} catch (FileNotFoundException e) {
_log.info("FileNotFoundException loading " + relativeFilename + " in " + bundleId + " bundle.");
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
long fileLength = requestedFile.length();
StreamingOutput output = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
FileChannel inChannel = null;
WritableByteChannel outChannel = null;
try {
inChannel = new FileInputStream(requestedFile).getChannel();
outChannel = Channels.newChannel(os);
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (outChannel != null)
outChannel.close();
if (inChannel != null)
inChannel.close();
}
}
};
ContentDisposition cd = ContentDisposition.type("file").fileName(requestedFile.getName()).build();
Response response = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", cd).header("Content-Length", fileLength).build();
_log.info("Returning Response in getBundleFile");
return response;
}
use of com.sun.jersey.core.header.ContentDisposition in project onebusaway-application-modules by camsys.
the class LocalBundleStagerServiceImpl method getBundleFile.
@Override
public Response getBundleFile(String bundleId, String relativeFilename) {
_log.info("starting getBundleFile for relative filename " + relativeFilename + " in bundle " + bundleId);
boolean requestIsForValidBundleFile = bundleProvider.checkIsValidBundleFile(bundleId, relativeFilename);
if (!requestIsForValidBundleFile) {
throw new WebApplicationException(new IllegalArgumentException(relativeFilename + " is not listed in bundle metadata."), Response.Status.BAD_REQUEST);
}
final File requestedFile;
try {
requestedFile = bundleProvider.getBundleFile(bundleId, relativeFilename);
} catch (FileNotFoundException e) {
_log.info("FileNotFoundException loading " + relativeFilename + " in " + bundleId + " bundle.");
throw new WebApplicationException(e, Response.Status.INTERNAL_SERVER_ERROR);
}
long fileLength = requestedFile.length();
StreamingOutput output = new StreamingOutput() {
@Override
public void write(OutputStream os) throws IOException, WebApplicationException {
FileChannel inChannel = null;
WritableByteChannel outChannel = null;
try {
inChannel = new FileInputStream(requestedFile).getChannel();
outChannel = Channels.newChannel(os);
inChannel.transferTo(0, inChannel.size(), outChannel);
} finally {
if (outChannel != null)
outChannel.close();
if (inChannel != null)
inChannel.close();
}
}
};
ContentDisposition cd = ContentDisposition.type("file").fileName(requestedFile.getName()).build();
Response response = Response.ok(output, MediaType.APPLICATION_OCTET_STREAM).header("Content-Disposition", cd).header("Content-Length", fileLength).build();
_log.info("Returning Response in getBundleFile");
return response;
}
Aggregations