/** * Load data by URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { InputStream input = null; try { input = UrlUtil.openStream(url); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(UrlUtil.openStream(url), stream); data = stream.toByteArray(); } finally { if (input != null) { input.close(); } } } }
/** * This method is invoked while deserialization */ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { in.defaultReadObject(); if (outputStream == null) { outputStream = new ByteArrayOutputStream().assignBytes(getDebugBytes()); } }
public void reset() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); currentPos = 0; } else throw new IOException(IOException.BytesCanBeResetInByteArrayOutputStreamOnly); }
@SuppressWarnings("unused") private byte[] getSerializedBytes() { ByteArrayOutputStream bos = null; ObjectOutputStream oos = null; try { bos = new ByteArrayOutputStream(); oos = new ObjectOutputStream(bos); oos.writeObject(this); oos.flush(); return bos.toByteArray(); } catch (Exception e) { Logger logger = LoggerFactory.getLogger(PdfDocument.class); logger.warn(LogMessageConstant.DOCUMENT_SERIALIZATION_EXCEPTION_RAISED, e); return null; } finally { if (oos != null) { try { oos.close(); } catch (IOException ignored) { } } if (bos != null) { try { bos.close(); } catch (IOException ignored) { } } } }
pdfStream.initOutputStream(new ByteArrayOutputStream(bytes.length)); pdfStream.getOutputStream().write(bytes); if (toCompress && !containsFlateFilter(pdfStream) && (allowCompression || userDefinedCompression)) { // compress updateCompressionFilter(pdfStream); byteArrayStream = new ByteArrayOutputStream(); DeflaterOutputStream zip = new DeflaterOutputStream(byteArrayStream, pdfStream.getCompressionLevel()); if (pdfStream instanceof PdfObjectStream) { PdfObjectStream objectStream = (PdfObjectStream) pdfStream; ((ByteArrayOutputStream) objectStream.getIndexStream().getOutputStream()).writeTo(zip); ((ByteArrayOutputStream) objectStream.getOutputStream().getOutputStream()).writeTo(zip); } else { assert pdfStream.getOutputStream() != null : "Error in outputStream"; ((ByteArrayOutputStream) pdfStream.getOutputStream().getOutputStream()).writeTo(zip); if (pdfStream instanceof PdfObjectStream) { PdfObjectStream objectStream = (PdfObjectStream) pdfStream; byteArrayStream = new ByteArrayOutputStream(); ((ByteArrayOutputStream) objectStream.getIndexStream().getOutputStream()).writeTo(byteArrayStream); ((ByteArrayOutputStream) objectStream.getOutputStream().getOutputStream()).writeTo(byteArrayStream); } else { assert pdfStream.getOutputStream() != null : "Error in outputStream"; ByteArrayOutputStream encodedStream = new ByteArrayOutputStream(); OutputStreamEncryption ose = crypto.getEncryptionStream(encodedStream); byteArrayStream.writeTo(ose); ose.finish(); byteArrayStream = encodedStream;
public PdfObjectStream(PdfDocument doc) { this(doc, new ByteArrayOutputStream()); indexStream = new PdfOutputStream(new ByteArrayOutputStream()); }
private byte[] getDebugBytes() throws IOException { if (duplicateStream != null) { duplicateStream.flush(); return ((ByteArrayOutputStream) (duplicateStream.getOutputStream())).toByteArray(); } else { return null; } }
public void assignBytes(byte[] bytes, int count) { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).assignBytes(bytes, count); currentPos = count; } else throw new IOException(IOException.BytesCanBeAssignedToByteArrayOutputStreamOnly); }
if (size < 0) return; png.idat.write(buffer, 0, size); len -= size;
/** * This method is called when another split document is to be created. * You can override this method and return your own {@link PdfWriter} depending on your needs. * * @param documentPageRange the page range of the original document to be included in the document being created now. * @return the PdfWriter instance for the document which is being created. */ protected PdfWriter getNextPdfWriter(PageRange documentPageRange) { return new PdfWriter(new ByteArrayOutputStream()); }
RawImageHelper.updateRawImageParameters(png.image, png.width, png.height, components, bpc, png.idat.toByteArray()); png.image.setDeflated(true); Map<String, Object> decodeparms = new HashMap<>();
public void assignBytes(byte[] bytes, int count) { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).assignBytes(bytes, count); currentPos = count; } else throw new IOException(IOException.BytesCanBeAssignedToByteArrayOutputStreamOnly); }
if (size < 0) return; png.idat.write(buffer, 0, size); len -= size;
/** * Load data by URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { InputStream input = null; try { input = UrlUtil.openStream(url); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(UrlUtil.openStream(url), stream); data = stream.toByteArray(); } finally { if (input != null) { input.close(); } } } }
private PdfWriter setDebugMode() { duplicateStream = new PdfOutputStream(new ByteArrayOutputStream()); return this; }
RawImageHelper.updateRawImageParameters(png.image, png.width, png.height, components, bpc, png.idat.toByteArray()); png.image.setDeflated(true); Map<String, Object> decodeparms = new HashMap<>();
public void reset() { if (outputStream instanceof ByteArrayOutputStream) { ((ByteArrayOutputStream) outputStream).reset(); currentPos = 0; } else throw new IOException(IOException.BytesCanBeResetInByteArrayOutputStreamOnly); }
/** * Load data from URL. url must be not null. * Note, this method doesn't check if data or url is null. * @throws java.io.IOException */ void loadData() throws java.io.IOException { RandomAccessFileOrArray raf = new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(url)); ByteArrayOutputStream stream = new ByteArrayOutputStream(); StreamUtil.transferBytes(raf, stream); raf.close(); data = stream.toByteArray(); }
/** * This method is invoked while deserialization */ private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException { in.defaultReadObject(); if (outputStream == null && duplicateContentBuffer != null) { outputStream = new ByteArrayOutputStream(); write(duplicateContentBuffer); duplicateContentBuffer = null; } }
try { outputStream.getOutputStream().flush(); bytes = ((ByteArrayOutputStream) outputStream.getOutputStream()).toByteArray(); if (decoded && containsKey(PdfName.Filter)) { bytes = PdfReader.decodeBytes(bytes, this);