/** * @param file * @return the contents of a file in a byte array. * @throws DownloadException */ protected static byte[] getBytesFromFile(final File file) throws DownloadException { try { InputStream is = new FileInputStream(file); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IOException("file [" + file.getName() + "] is too large for download"); } byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = is.read(bytes, offset, bytes.length - offset); while (offset < bytes.length && numRead >= 0) { offset += numRead; numRead = is.read(bytes, offset, bytes.length - offset); } if (offset < bytes.length) { throw new IOException("could not completely read file [" + file.getName() + "]"); } is.close(); return bytes; } catch (Throwable t) { throw new DownloadException(t); } }
/** * @param file * @return the contents of a file in a byte array. * @throws DownloadException */ protected static byte[] getBytesFromFile(final File file) throws DownloadException { try { InputStream is = new FileInputStream(file); long length = file.length(); if (length > Integer.MAX_VALUE) { throw new IOException("file [" + file.getName() + "] is too large for download"); } byte[] bytes = new byte[(int) length]; int offset = 0; int numRead = is.read(bytes, offset, bytes.length - offset); while (offset < bytes.length && numRead >= 0) { offset += numRead; numRead = is.read(bytes, offset, bytes.length - offset); } if (offset < bytes.length) { throw new IOException("could not completely read file [" + file.getName() + "]"); } is.close(); return bytes; } catch (Throwable t) { throw new DownloadException(t); } }
return bytes; } catch (Throwable t) { throw new DownloadException(t); } finally { try {
String id = request.getParameter(ID_ATTRIBUTE); if (id == null) { throw new DownloadException( "attribute " + ID_ATTRIBUTE + " not found, can not download"); DATA_ATTRIBUTE + id); if (data == null) { throw new DownloadException("data is null, can not download"); Exception de = new DownloadException(t);
throw e; } catch (Throwable t) { throw new DownloadException(t);
throw e; } catch (Throwable t) { throw new DownloadException(t);
throw e; } catch (Throwable t) { throw new DownloadException(t);