org.apache.pdfbox.io.IOUtils类的使用及代码示例

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

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

IOUtils介绍

[英]This class contains various I/O-related methods.
[中]此类包含各种与I/O相关的方法。

代码示例

代码示例来源: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

output.write(request);
IOUtils.closeQuietly(output);
response = IOUtils.toByteArray(input);
IOUtils.closeQuietly(input);

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

firstException = IOUtils.closeAndLogException(signingSupport, LOG, "SigningSupport", firstException);
firstException = IOUtils.closeAndLogException(document, LOG, "COSDocument", firstException);
  firstException = IOUtils.closeAndLogException(pdfSource, LOG, "RandomAccessRead pdfSource", firstException);
  firstException = IOUtils.closeAndLogException(ttf, LOG, "TrueTypeFont", firstException);

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

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

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

final int[] readCIDToGIDMap() throws IOException
  {
    int[] cid2gid = null;
    COSBase map = dict.getDictionaryObject(COSName.CID_TO_GID_MAP);
    if (map instanceof COSStream)
    {
      COSStream stream = (COSStream) map;

      InputStream is = stream.createInputStream();
      byte[] mapAsBytes = IOUtils.toByteArray(is);
      IOUtils.closeQuietly(is);
      int numberOfInts = mapAsBytes.length / 2;
      cid2gid = new int[numberOfInts];
      int offset = 0;
      for (int index = 0; index < numberOfInts; index++)
      {
        int gid = (mapAsBytes[offset] & 0xff) << 8 | mapAsBytes[offset + 1] & 0xff;
        cid2gid[index] = gid;
        offset += 2;
      }
    }
    return cid2gid;
  }
}

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

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

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

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

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

public void addCompression()
  List<COSName> filters = getFilters();
  if (filters == null)
      try
        byte[] bytes = IOUtils.toByteArray(stream.createInputStream());
        out = stream.createOutputStream(COSName.FLATE_DECODE);
        out.write(bytes);
        IOUtils.closeQuietly(out);
      setFilters(filters);

代码示例来源:origin: org.apache.pdfbox/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
{
  OutputStream output = null;
  try
  {
    stream = doc.getDocument().createCOSStream();
    output = stream.createOutputStream(filters);
    IOUtils.copy(input, output);
  }
  finally
  {
    if (output != null)
    {
      output.close();
    }
    if (input != null)
    {
      input.close();
    }
  }
}

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

PDDeviceRGB.INSTANCE.getName().equals(colorSpaceName)) {
      InputStream data = pdImage.getStream().createInputStream(JPEG);
      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{
    ImageIOUtil.writeImage(image, suffix, out);
out.flush();

代码示例来源:origin: org.apache.pdfbox/pdfbox-examples

/**
 * Creates a Flate encoded <code>COSStream</code> object with the given data.
 * 
 * @param data to write into the COSStream
 * @return COSStream a COSStream object that can be added to the document
 * @throws IOException
 */
private COSStream writeDataToStream(byte[] data) throws IOException
{
  COSStream stream = document.getDocument().createCOSStream();
  OutputStream os = null;
  try
  {
    os = stream.createOutputStream(COSName.FLATE_DECODE);
    os.write(data);
  }
  finally
  {
    IOUtils.closeQuietly(os);
  }
  return stream;
}

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

/**
 * This will encrypt a stream, but not the dictionary as the dictionary is
 * encrypted by visitFromString() in COSWriter and we don't want to encrypt
 * it twice.
 *
 * @param stream The stream to decrypt.
 * @param objNum The object number.
 * @param genNum The object generation number.
 *
 * @throws IOException If there is an error getting the stream data.
 */
public void encryptStream(COSStream stream, long objNum, int genNum) throws IOException
{
  byte[] rawData = IOUtils.toByteArray(stream.createRawInputStream());
  ByteArrayInputStream encryptedStream = new ByteArrayInputStream(rawData);
  OutputStream output = stream.createRawOutputStream();
  try
  {
    encryptData(objNum, genNum, encryptedStream, output, false /* encrypt */);
  }
  finally
  {
    output.close();
  }
}

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

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

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

@Override
  public void actionPerformed(ActionEvent actionEvent)
  {
    try
    {
      InputStream data = stream.createInputStream(stopFilters);
      saveStream(IOUtils.toByteArray(data), null, null);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
});

代码示例来源: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

private static List<File> listFiles(String path) throws IOException
  {
    List<File> files = new ArrayList<>();
    File f = new File(path);
    if (f.isFile())
    {
      FileReader fr = new FileReader(f);
      BufferedReader buf = new BufferedReader(fr);
      while (buf.ready())
      {
        File fn = new File(buf.readLine());
        if (fn.exists())
        {
          files.add(fn);
        } // else warn ?
      }
      IOUtils.closeQuietly(buf);
    }
    else
    {
      File[] fileList = f.listFiles();
      if (fileList != null)
      {
        files.addAll(Arrays.asList(fileList));
      }
    }
    return files;
  }
}

代码示例来源: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: org.apache.pdfbox/pdfbox

public void buildFontFile2(InputStream ttfStream) throws IOException
{
  PDStream stream = new PDStream(document, ttfStream, COSName.FLATE_DECODE);
  // as the stream was closed within the PDStream constructor, we have to recreate it
  InputStream input = null;
  try
  {
    input = stream.createInputStream();
    ttf = new TTFParser().parseEmbedded(input);
    if (!isEmbeddingPermitted(ttf))
    {
      throw new IOException("This font does not permit embedding");
    }
    if (fontDescriptor == null)
    {
      fontDescriptor = createFontDescriptor(ttf);
    }
  }
  finally
  {
    IOUtils.closeQuietly(input);
  }
  stream.getCOSObject().setLong(COSName.LENGTH1, ttf.getOriginalDataSize());
  fontDescriptor.setFontFile2(stream);
}

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

public byte[] toByteArray() throws IOException 
 {
   return IOUtils.toByteArray(this);
 }
}

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

/**
 * Creates an Image XObject with the given stream as its contents and current color spaces. This
 * constructor is for internal PDFBox use and is not for PDF generation. Users who want to
 * create images should look at {@link #createFromFileByExtension(File, PDDocument) }.
 *
 * @param stream the XObject stream to read
 * @param resources the current resources
 * @throws java.io.IOException if there is an error creating the XObject.
 */
public PDImageXObject(PDStream stream, PDResources resources) throws IOException
{
  super(stream, COSName.IMAGE);
  this.resources = resources;
  List<COSName> filters = stream.getFilters();
  if (filters != null && !filters.isEmpty() && COSName.JPX_DECODE.equals(filters.get(filters.size()-1)))
  {
    COSInputStream is = null;
    try
    {
      is = stream.createInputStream();
      DecodeResult decodeResult = is.getDecodeResult();
      stream.getCOSObject().addAll(decodeResult.getParameters());
      this.colorSpace = decodeResult.getJPXColorSpace();
    }
    finally
    {
      IOUtils.closeQuietly(is);
    }
  }
}

相关文章