org.apache.pdfbox.io.IOUtils.copy()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.2k)|赞(0)|评价(0)|浏览(299)

本文整理了Java中org.apache.pdfbox.io.IOUtils.copy()方法的一些代码示例,展示了IOUtils.copy()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IOUtils.copy()方法的具体详情如下:
包路径:org.apache.pdfbox.io.IOUtils
类名称:IOUtils
方法名:copy

IOUtils.copy介绍

[英]Copies all the contents from the given input stream to the given output stream.
[中]将所有内容从给定的输入流复制到给定的输出流。

代码示例

代码示例来源:origin: apache/pdfbox

@Override
  protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
    throws IOException
  {
    IOUtils.copy(input, encoded);
    encoded.flush();
  }
}

代码示例来源:origin: apache/pdfbox

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

代码示例来源:origin: apache/pdfbox

/**
 * Reads the input stream and returns its contents as a byte array.
 * @param in the input stream to read from.
 * @return the byte array
 * @throws IOException if an I/O error occurs
 */
public static byte[] toByteArray(InputStream in) throws IOException
{
  ByteArrayOutputStream baout = new ByteArrayOutputStream();
  copy(in, baout);
  return baout.toByteArray();
}

代码示例来源:origin: apache/pdfbox

private String getStringOfStream(InputStream in, String encoding)
{
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try
  {
    IOUtils.copy(in, baos);
    return baos.toString(encoding);
  }
  catch (IOException e)
  {
    e.printStackTrace();
    return null;
  }
}

代码示例来源:origin: apache/pdfbox

@Override
public DecodeResult decode(InputStream encoded, OutputStream decoded,
                   COSDictionary parameters, int index)
  throws IOException
{
  IOUtils.copy(encoded, decoded);
  decoded.flush();
  return new DecodeResult(parameters);
}

代码示例来源:origin: apache/pdfbox

@Override
  protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
    throws IOException
  {
    try (ASCII85OutputStream os = new ASCII85OutputStream(encoded))
    {
      IOUtils.copy(input, os);
    }
    encoded.flush();
  }
}

代码示例来源:origin: apache/pdfbox

public ByteArrayDataSource(InputStream is) throws IOException
{
  data = new ByteArrayOutputStream();
  IOUtils.copy(is, data);
  IOUtils.closeQuietly(is);
}

代码示例来源:origin: apache/pdfbox

private File createTmpFile(InputStream input) throws IOException
{
  File tmpFile = File.createTempFile(TMP_FILE_PREFIX, ".pdf");
  try (FileOutputStream fos = new FileOutputStream(tmpFile))
  {
    IOUtils.copy(input, fos);
    return tmpFile;
  }
  finally
  {
    IOUtils.closeQuietly(input);
  }
}

代码示例来源:origin: apache/pdfbox

/**
 * Write an incremental update for a non signature case. This can be used for e.g. augmenting
 * signatures.
 *
 * @throws IOException
 */
private void doWriteIncrement() throws IOException
{
  // write existing PDF
  IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
  // write the actual incremental update
  incrementalOutput.write(((ByteArrayOutputStream) output).toByteArray());
}

代码示例来源:origin: apache/pdfbox

/**
 * This will copy the stream into a byte array.
 * 
 * @return The byte array of the filteredStream.
 * @throws IOException if an I/O error occurs.
 */
public byte[] toByteArray() throws IOException
{
  ByteArrayOutputStream output = new ByteArrayOutputStream();
  try (InputStream is = createInputStream())
  {
    IOUtils.copy(is, output);
  }
  return output.toByteArray();
}

代码示例来源:origin: apache/pdfbox

@Override
public DecodeResult decode(InputStream encoded, OutputStream decoded,
                   COSDictionary parameters, int index) throws IOException
{
  try (ASCII85InputStream is = new ASCII85InputStream(encoded))
  {
    IOUtils.copy(is, decoded);
  }
  decoded.flush();
  return new DecodeResult(parameters);
}

代码示例来源:origin: apache/pdfbox

private void writeFont(PDFontDescriptor fd, String name) throws IOException
{
  if (fd != null)
  {
    PDStream ff2Stream = fd.getFontFile2();
    if (ff2Stream != null)
    {
      System.out.println("Writing font: " + name);
      try (OutputStream os = new FileOutputStream(new File(name + ".ttf"));
         InputStream is = ff2Stream.createInputStream())
      {
        IOUtils.copy(is, os);
      }
    }
  }
}

代码示例来源:origin: apache/pdfbox

@Override
  protected void encode(InputStream input, OutputStream encoded, COSDictionary parameters)
      throws IOException
  {
    int cols = parameters.getInt(COSName.COLUMNS);
    int rows = parameters.getInt(COSName.ROWS);
    CCITTFaxEncoderStream ccittFaxEncoderStream = 
        new CCITTFaxEncoderStream(encoded, cols, rows, TIFFExtension.FILL_LEFT_TO_RIGHT);
    IOUtils.copy(input, ccittFaxEncoderStream);
    input.close();
  }
}

代码示例来源:origin: apache/pdfbox

/**
 * Write externally created signature of PDF data obtained via {@link #getDataToSign()} method.
 *
 * @param cmsSignature CMS signature byte array
 * @throws IllegalStateException if PDF is not prepared for external signing
 * @throws IOException if source data stream is closed
 */
public void writeExternalSignature(byte[] cmsSignature) throws IOException
{
  if (incrementPart == null || incrementalInput == null)
  {
    throw new IllegalStateException("PDF not prepared for setting signature");
  }
  byte[] signatureBytes = Hex.getBytes(cmsSignature);
  // substract 2 bytes because of the enclosing "<>"
  if (signatureBytes.length > signatureLength - 2)
  {
    throw new IOException("Can't write signature, not enough space");
  }
  // overwrite the signature Contents in the buffer
  int incPartSigOffset = (int) (signatureOffset - incrementalInput.length());
  System.arraycopy(signatureBytes, 0, incrementPart, incPartSigOffset + 1, signatureBytes.length);
  // write the data to the incremental output stream
  IOUtils.copy(new RandomAccessInputStream(incrementalInput), incrementalOutput);
  incrementalOutput.write(incrementPart);
  // prevent further use
  incrementPart = null;
}

代码示例来源:origin: apache/pdfbox

/**
 * Constructor. Reads all data from the input stream and embeds it into the document with the
 * given filters applied, if any. This method closes the InputStream.
 */
private PDStream(PDDocument doc, InputStream input, COSBase filters) throws IOException
{
  stream = doc.getDocument().createCOSStream();
  try (OutputStream output = stream.createOutputStream(filters))
  {
    IOUtils.copy(input, output);
  }
  finally
  {
    if (input != null)
    {
      input.close();
    }
  }
}

代码示例来源:origin: apache/pdfbox

/**
 * Creates a COS stream from raw (encoded) data.
 */
private static COSStream createRawStream(PDDocument document, InputStream rawInput)
    throws IOException
{
  COSStream stream = document.getDocument().createCOSStream();
  try (OutputStream output = stream.createRawOutputStream())
  {
    IOUtils.copy(rawInput, output);
  }
  return stream;
}

代码示例来源:origin: apache/pdfbox

/**
 * Returns the contents of the stream as a PDF "text string".
 */
public String toTextString()
{
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  InputStream input = null;
  try
  {
    input = createInputStream();
    IOUtils.copy(input, out);
  }
  catch (IOException e)
  {
    LOG.debug("An exception occured trying to get the content - returning empty string instead", e);
    return "";
  }
  finally
  {
    IOUtils.closeQuietly(input);
  }
  COSString string = new COSString(out.toByteArray());
  return string.getString();
}

代码示例来源:origin: apache/tika

org.apache.pdfbox.io.IOUtils.copy(data, out);
    org.apache.pdfbox.io.IOUtils.closeQuietly(data);
  } else {
  org.apache.pdfbox.io.IOUtils.copy(data, out);
  org.apache.pdfbox.io.IOUtils.closeQuietly(data);
} else if ("jb2".equals(suffix)) {
  InputStream data = pdImage.createInputStream(JB2);
  org.apache.pdfbox.io.IOUtils.copy(data, out);
  org.apache.pdfbox.io.IOUtils.closeQuietly(data);
} else{

代码示例来源:origin: apache/pdfbox

private COSStream createCombinedContentStream(COSBase contents) throws IOException
{
  List<COSStream> contentStreams = createContentStreamList(contents);
  // concatenate streams
  COSStream concatStream = inputPDFDocument.getDocument().createCOSStream();
  try (OutputStream out = concatStream.createOutputStream(COSName.FLATE_DECODE))
  {
    for (COSStream contentStream : contentStreams)
    {
      try (InputStream in = contentStream.createInputStream())
      {
        IOUtils.copy(in, out);
        out.flush();
      }
    }
  }
  return concatStream;
}

代码示例来源:origin: apache/pdfbox

IOUtils.copy(input, getStandardOutput());

相关文章