Exemplo n.º 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;
  }
Exemplo n.º 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;
 }
Exemplo n.º 3
0
  private BinaryData getBinaryData(
      ContentBinaryDataEntity contentBinaryData, boolean anonAccess, long timestamp) {
    BinaryData binaryData = new BinaryData();
    binaryData.key = contentBinaryData.getBinaryData().getKey();
    binaryData.contentKey = contentBinaryData.getContentVersion().getContent().getKey().toInt();
    binaryData.setSafeFileName(contentBinaryData.getBinaryData().getName());
    binaryData.timestamp = contentBinaryData.getBinaryData().getCreatedAt();
    binaryData.anonymousAccess = anonAccess;

    if (binaryData.timestamp.getTime() > timestamp) {
      BlobRecord blob = this.binaryDataDao.getBlob(contentBinaryData.getBinaryData());
      binaryData.data = blob.getAsBytes();
    }

    return binaryData;
  }