Example usage for org.apache.pdfbox.io IOUtils copy

List of usage examples for org.apache.pdfbox.io IOUtils copy

Introduction

In this page you can find the example usage for org.apache.pdfbox.io IOUtils copy.

Prototype

public static long copy(InputStream input, OutputStream output) throws IOException 

Source Link

Document

Copies all the contents from the given input stream to the given output stream.

Usage

From source file:CMSProcessableInputStream.java

License:Apache License

public void write(OutputStream out) throws IOException, CMSException {
    // read the content only one time
    IOUtils.copy(in, out);
    in.close();
}

From source file:com.ackpdfbox.app.CMSProcessableInputStream.java

License:Apache License

@Override
public void write(OutputStream out) throws IOException, CMSException {
    // read the content only one time
    IOUtils.copy(in, out);
    in.close();//from w  w w. j a va2s. co  m
}

From source file:cz.incad.kramerius.rest.api.replication.ReplicationsResource.java

License:Open Source License

@GET
@Path("img_original")
@Produces("image/jp2")
public Response getOriginalImage(@PathParam("pid") String pid) throws XPathExpressionException, IOException {
    String tilesUrl = RelsExtHelper.getRelsExtTilesUrl(fedoraAccess.getRelsExt(pid));
    if (tilesUrl == null)
        return Response.status(Response.Status.NOT_FOUND).build();

    HttpClient httpclient = HttpClients.createDefault();
    final HttpResponse httpResponse = httpclient.execute(new HttpGet(tilesUrl + "/original"));

    switch (httpResponse.getStatusLine().getStatusCode()) {
    case 200://from   w w  w  .j  av  a 2 s  .c om
        break;
    case 404:
        return Response.status(Response.Status.NOT_FOUND).build();
    default:
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }

    StreamingOutput stream = new StreamingOutput() {
        @Override
        public void write(OutputStream output) throws IOException, WebApplicationException {
            IOUtils.copy(httpResponse.getEntity().getContent(), output);
            output.flush();
        }
    };
    return Response.ok(stream).build();
}

From source file:de.rototor.pdfbox.graphics2d.PdfBoxGraphics2DFontTextDrawer.java

License:Apache License

/**
 * Register a font. If possible, try to use a font file, i.e.
 * {@link #registerFont(String,File)}. This method will lead to the creation of
 * a temporary file which stores the font data.
 * // www. j a va2  s .  co m
 * @param fontName
 *            the name of the font to use. If null, the name is taken from the
 *            font.
 * @param fontStream
 *            the input stream of the font. This file must be a ttf/otf file!
 *            You have to close the stream outside, this method will not close
 *            the stream.
 * @throws IOException
 *             when something goes wrong with reading the font or writing the
 *             font to the content stream of the PDF:
 */
@SuppressWarnings("WeakerAccess")
public void registerFont(String fontName, InputStream fontStream) throws IOException {
    File fontFile = File.createTempFile("pdfboxgfx2dfont", ".ttf");
    FileOutputStream out = new FileOutputStream(fontFile);
    try {
        IOUtils.copy(fontStream, out);
    } finally {
        out.close();
    }
    fontFile.deleteOnExit();
    tempFiles.add(fontFile);
    registerFont(fontName, fontFile);
}

From source file:eu.europa.esig.dss.pades.signature.PAdESVisibleSignaturePositionTest.java

License:Open Source License

@Test
@Ignore("for generation and manual testing")
public void rotateTest() throws Exception {
    SignatureImageParameters signatureImageParameters = createSignatureImageParameters();

    signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
    DSSDocument document = sign(signablePdfs.get("minoltaScan90"));
    File checkPdfFile = new File("target/pdf/check.pdf");
    checkPdfFile.getParentFile().mkdirs();
    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}

From source file:eu.europa.esig.dss.pades.signature.PAdESVisibleSignaturePositionTest.java

License:Open Source License

@Test
@Ignore("for generation and manual testing")
public void bigGeneratorTest() throws Exception {
    SignatureImageParameters signatureImageParameters = createSignatureImageParameters();

    for (SignatureImageParameters.VisualSignatureRotation rotation : SignatureImageParameters.VisualSignatureRotation
            .values()) {//from  w ww  .ja  v  a2s . com
        for (SignatureImageParameters.VisualSignatureAlignmentHorizontal horizontal : SignatureImageParameters.VisualSignatureAlignmentHorizontal
                .values()) {
            for (SignatureImageParameters.VisualSignatureAlignmentVertical vertical : SignatureImageParameters.VisualSignatureAlignmentVertical
                    .values()) {
                signatureImageParameters.setRotation(rotation);
                signatureImageParameters.setAlignmentHorizontal(horizontal);
                signatureImageParameters.setAlignmentVertical(vertical);
                String[] pdfs = new String[] { "normal", "90", "180", "270" };
                for (String pdf : pdfs) {
                    DSSDocument document = sign(signablePdfs.get(pdf));
                    File checkPdfFile = new File("target/pdf/check_" + rotation.name() + "_" + pdf + "_"
                            + horizontal.name() + "_" + vertical.name() + ".pdf");
                    checkPdfFile.getParentFile().mkdirs();
                    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
                }
            }
        }
    }
}

From source file:eu.europa.esig.dss.pades.signature.PAdESVisibleSignaturePositionTest.java

License:Open Source License

@Test
@Ignore("for pull request #71")
public void rotatePullRequest71Test() throws Exception {
    Logger logger = LoggerFactory.getLogger(getClass());
    /**//from  w  ww  .j  ava 2 s  . co  m
     * minolta scanner normal(not rotated) pdf and rotation none.
     *
     * You can check the pdf rotation by this code:
     * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
     * System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
     *
     * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes line
     *
     * comment: this is the original working
     */
    PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun.pdf"));
    logger.info("rotation sun.pdf: " + inputPDF.getPage(0).getRotation());

    SignatureImageParameters signatureImageParameters = createSignatureImageParameters();

    signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
    DSSDocument document = sign(signablePdfs.get("minoltaScan"));
    File checkPdfFile = new File("target/pdf/check_normal_none.pdf");
    checkPdfFile.getParentFile().mkdirs();
    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

    /**
     * minolta scanner rotated pdf and rotation none (in pdf view the rotated and normal pdf seem equal)
     * you can check the pdf rotation by this code:
     * PDDocument inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
     * System.out.println("rotation: " + inputPDF.getPage(0).getRotation());
     *
     * result in pdf viewer: signature is top right corner and the sign image line is perpendicular with the sun
     * eyes line
     *
     * comment: this is the original working
     */
    inputPDF = PDDocument.load(getClass().getResourceAsStream("/visualSignature/sun_90.pdf"));
    logger.info("rotation sun_90.pdf: " + inputPDF.getPage(0).getRotation());

    signatureImageParameters = createSignatureImageParameters();

    signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.NONE);
    document = sign(signablePdfs.get("minoltaScan90"));
    checkPdfFile = new File("target/pdf/check_90_none.pdf");
    checkPdfFile.getParentFile().mkdirs();
    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

    /**
     * minolta scanner rotated pdf and rotation automatic (in pdf view the rotated and normal pdf seem equal)
     *
     * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes
     * line,
     * it will be same as with sun.pdf (not rotated) and rotation none
     */
    signatureImageParameters = createSignatureImageParameters();

    signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
    document = sign(signablePdfs.get("minoltaScan90"));
    checkPdfFile = new File("target/pdf/check_90_automatic.pdf");
    checkPdfFile.getParentFile().mkdirs();
    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));

    /**
     * minolta scanner normal(not rotated) pdf and rotation none.
     *
     * result in pdf viewer: signature is top left corner and the sign image line is parallel with the sun eyes
     * line,
     * it will be same as with sun.pdf (not rotated) and rotation none
     */
    signatureImageParameters = createSignatureImageParameters();

    signatureImageParameters.setRotation(SignatureImageParameters.VisualSignatureRotation.AUTOMATIC);
    document = sign(signablePdfs.get("minoltaScan"));
    checkPdfFile = new File("target/pdf/check_normal_automatic.pdf");
    checkPdfFile.getParentFile().mkdirs();
    IOUtils.copy(document.openStream(), new FileOutputStream(checkPdfFile));
}

From source file:org.apache.padaf.xmpbox.parser.XMPDocumentBuilder.java

License:Apache License

private byte[] getStreamAsByteArray(InputStream input) throws XmpParsingException {
    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    try {//w  ww .  ja v a  2s .co  m
        IOUtils.copy(input, bos);
    } catch (IOException e) {
        throw new XmpParsingException("An error has occured when processing the underlying XMP source", e);
    } finally {
        IOUtils.closeQuietly(bos);
        IOUtils.closeQuietly(input);
    }
    return bos.toByteArray();
}

From source file:org.mustangproject.ZUGFeRD.ZUGFeRDExporterFromA3Factory.java

License:Open Source License

private static byte[] readAllBytes(InputStream in) throws IOException {
    ByteArrayOutputStream buffer = new ByteArrayOutputStream();
    IOUtils.copy(in, buffer);
    return buffer.toByteArray();
}

From source file:org.structr.web.servlet.DeploymentServlet.java

License:Open Source License

/**
 * Unzip given file to given output directory.
 *
 * @param file//  w w w .  ja v  a2 s  .  c o m
 * @param outputDir
 * @throws IOException
 */
private void unzip(final File file, final String outputDir) throws IOException {

    try (final ZipFile zipFile = new ZipFile(file)) {

        final Enumeration<? extends ZipEntry> entries = zipFile.entries();

        while (entries.hasMoreElements()) {

            final ZipEntry entry = entries.nextElement();
            final File targetFile = new File(outputDir, entry.getName());

            if (entry.isDirectory()) {

                targetFile.mkdirs();

            } else {

                targetFile.getParentFile().mkdirs();
                InputStream in = zipFile.getInputStream(entry);

                try (OutputStream out = new FileOutputStream(targetFile)) {

                    IOUtils.copy(in, out);
                    IOUtils.closeQuietly(in);
                }
            }
        }
    }
}