Пример #1
0
  public static BinaryData createBinaryData(final FileItem fileItem, final String label)
      throws VerticalAdminException {
    BinaryData binaryData = new BinaryData();
    InputStream fis = null;
    try {
      binaryData.fileName = FileUtil.getFileName(fileItem);

      fis = fileItem.getInputStream();
      ByteArrayOutputStream bao = new ByteArrayOutputStream();

      byte[] buf = new byte[1024 * 10];
      int size;
      while ((size = fis.read(buf)) > 0) {
        bao.write(buf, 0, size);
      }
      binaryData.data = bao.toByteArray();
      binaryData.label = label;
    } catch (IOException e) {
      VerticalAdminLogger.errorAdmin(AdminHandlerBaseServlet.class, 20, "I/O error: %t", e);
    } finally {
      try {
        if (fis != null) {
          fis.close();
        }
      } catch (IOException ioe) {
        String message = "Failed to close file input stream: %t";
        VerticalAdminLogger.warn(AdminHandlerBaseServlet.class, 0, message, ioe);
      }
    }
    return binaryData;
  }
Пример #2
0
 public static BinaryData createBinaryDataFromStream(
     final ByteArrayOutputStream stream, final String fileName, final String label) {
   final BinaryData binaryData = new BinaryData();
   binaryData.fileName = fileName;
   binaryData.data = stream.toByteArray();
   binaryData.label = label;
   return binaryData;
 }