コード例 #1
0
  // public static Part getBinaryPart(ZipFile zf, ContentTypeManager ctm, String resolvedPartUri)
  public static Part getBinaryPart(
      HashMap<String, ByteArray> partByteArrays, ContentTypeManager ctm, String resolvedPartUri)
      throws Docx4JException {

    Part part = null;
    InputStream in = null;
    try {
      // in = zf.getInputStream( zf.getEntry(resolvedPartUri ) );
      in = partByteArrays.get(resolvedPartUri).getInputStream();
      part = new BinaryPart(new PartName("/" + resolvedPartUri));

      // Set content type
      part.setContentType(new ContentType(ctm.getContentType(new PartName("/" + resolvedPartUri))));

      ((BinaryPart) part).setBinaryData(in);
      log.info("Stored as BinaryData");

    } catch (Exception ioe) {
      ioe.printStackTrace();
    } finally {
      if (in != null) {
        try {
          in.close();
        } catch (IOException exc) {
          exc.printStackTrace();
        }
      }
    }
    return part;
  }
コード例 #2
0
ファイル: Load3.java プロジェクト: jspark67/docx4j
  public Part getBinaryPart(ContentTypeManager ctm, String resolvedPartUri) throws Docx4JException {

    Part part = null;
    InputStream is = null;
    try {
      is = partStore.loadPart(resolvedPartUri);
      // in = partByteArrays.get(resolvedPartUri).getInputStream();
      part = new BinaryPart(new PartName("/" + resolvedPartUri));

      // Set content type
      part.setContentType(new ContentType(ctm.getContentType(new PartName("/" + resolvedPartUri))));

      ((BinaryPart) part).setBinaryData(is);
      log.info("Stored as BinaryData");

    } catch (Exception ioe) {
      ioe.printStackTrace();
    } finally {
      IOUtils.closeQuietly(is);
    }
    return part;
  }