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

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

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

IOUtils.toByteArray介绍

[英]Reads the input stream and returns its contents as a byte array.
[中]读取输入流并将其内容作为字节数组返回。

代码示例

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

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

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

private static byte[] getBytesFromStream(final COSStream stream) throws IOException
{
  try (final InputStream is = stream.createInputStream())
  {
    return IOUtils.toByteArray(is);
  }
}

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

/**
 * Creates a signed timestamp token by the given input stream.
 * 
 * @param content InputStream of the content to sign
 * @return the byte[] of the timestamp token
 * @throws IOException
 */
public byte[] getTimeStampToken(InputStream content) throws IOException
{
  return tsaClient.getTimeStampToken(IOUtils.toByteArray(content));
}

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

@Override
  public void actionPerformed(ActionEvent actionEvent)
  {
    try
    {
      byte[] bytes = IOUtils.toByteArray(cosStream.createInputStream());
      saveStream(bytes, fileFilter, extension);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
});

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

/**
 * Creates a new JPEG Image XObject from an input stream containing JPEG data.
 * 
 * The input stream data will be preserved and embedded in the PDF file without modification.
 * @param document the document where the image will be created
 * @param stream a stream of JPEG data
 * @return a new Image XObject
 * 
 * @throws IOException if the input stream cannot be read
 */
public static PDImageXObject createFromStream(PDDocument document, InputStream stream)
    throws IOException
{
  return createFromByteArray(document, IOUtils.toByteArray(stream));
}

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

@Override
  public void actionPerformed(ActionEvent actionEvent)
  {
    try
    {
      byte[] bytes = IOUtils.toByteArray(cosStream.createRawInputStream());
      saveStream(bytes, null, null);
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
});

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

@Override
  public void actionPerformed(ActionEvent actionEvent)
  {
    try
    {
      byte[] bytes = IOUtils.toByteArray(cosStream.createInputStream());
      File temp = File.createTempFile("pdfbox", "." + extension);
      temp.deleteOnExit();
      try (FileOutputStream outputStream = new FileOutputStream(temp))
      {
        outputStream.write(bytes);
        Desktop.getDesktop().open(temp);
      }
    }
    catch (IOException e)
    {
      e.printStackTrace();
    }
  }
});

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

response = IOUtils.toByteArray(input);

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

try (FileInputStream fis = new FileInputStream(fileName))
  documentBytes = IOUtils.toByteArray(fis);

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

@Override
  public byte[] getBytes() throws IOException
  {
    PDStream ff3Stream = getFontDescriptor().getFontFile3();
    return IOUtils.toByteArray(ff3Stream.createInputStream());
  }
}

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

@Override
  public byte[] getBytes() throws IOException
  {
    PDStream ff3Stream = getFontDescriptor().getFontFile3();
    return IOUtils.toByteArray(ff3Stream.createInputStream());
  }
}

代码示例来源:origin: apache/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);
  try (OutputStream output = stream.createRawOutputStream())
  {
    encryptData(objNum, genNum, encryptedStream, output, false /* encrypt */);
  }
}

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

protected final byte[] getMetaDataStreamAsBytes(PDMetadata metadata)
{
  try (InputStream metaDataContent = metadata.createInputStream())
  {
    return IOUtils.toByteArray(metaDataContent);
  }
  catch (IOException e)
  {
    this.fContainer.push(new ValidationError(ERROR_METADATA_FORMAT_STREAM,
        this.font.getName() + ": Unable to read font metadata due to : " + e.getMessage(), e));
    return null;
  }
}

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

private void requestStreamText(String command) throws IOException
{
  new DocumentCreator(command).execute();
  synchronized (stream)
  {
    InputStream is = stream.getStream(command);
    if (is == null)
    {
      JOptionPane.showMessageDialog(panel, command + " text not available (filter missing?)");
      return;
    }
    hexView.changeData(IOUtils.toByteArray(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

try
  byte[] bytes = IOUtils.toByteArray(stream.createInputStream());
  out = stream.createOutputStream(COSName.FLATE_DECODE);
  out.write(bytes);

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

/**
 * Go through the elements of a COSArray containing each an COSStream to print in Hex.
 * 
 * @param elements COSArray of elements containing a COS Stream
 * @param description to append on Print
 * @throws IOException
 */
private void printStreamsFromArray(COSArray elements, String description) throws IOException
{
  for (COSBase baseElem : elements)
  {
    COSObject streamObj = (COSObject) baseElem;
    if (streamObj.getObject() instanceof COSStream)
    {
      COSStream cosStream = (COSStream) streamObj.getObject();
      try (InputStream is = cosStream.createInputStream())
      {
        byte[] streamBytes = IOUtils.toByteArray(is);
        System.out.println(description + " (" + elements.indexOf(streamObj) + "): "
          + Hex.getString(streamBytes));
      }
    }
  }
}

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

private StyledDocument getContentStreamDocument(InputStream inputStream)
{
  StyledDocument docu = new DefaultStyledDocument();
  PDFStreamParser parser;
  try
  {
    parser = new PDFStreamParser(IOUtils.toByteArray(inputStream));
    parser.parse();
  }
  catch (IOException e)
  {
    return null;
  }
  for (Object obj : parser.getTokens())
  {
    writeToken(obj, docu);
  }
  return docu;
}

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

byte[] mapAsBytes = IOUtils.toByteArray(is);
IOUtils.closeQuietly(is);
int numberOfInts = mapAsBytes.length / 2;

相关文章