Package com.itextpdf.text.io

Examples of com.itextpdf.text.io.RandomAccessSourceFactory


            return ps.toUnicodeString();
    }

    private void fillMetrics(byte[] touni, IntHashtable widths, int dw) {
        try {
            PdfContentParser ps = new PdfContentParser(new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(touni))));
            PdfObject ob = null;
            boolean notFound = true;
            int nestLevel = 0;
            int maxExc = 50;
            while ((notFound || nestLevel > 0)) {
View Full Code Here


     * @param filename
     * @throws IOException
     */
    @Deprecated
    public RandomAccessFileOrArray(String filename) throws IOException {
      this(new RandomAccessSourceFactory()
    .setForceRead(false)
    .setUsePlainRandomAccess(Document.plainRandomAccess)
    .createBestSource(filename));
     
    }
View Full Code Here

     * @throws IOException if there is a failure opening or reading the file
     * @deprecated use {@link RandomAccessSourceFactory#createBestSource(String)} and {@link RandomAccessFileOrArray#RandomAccessFileOrArray(RandomAccessSource)} instead
     */
    @Deprecated
    public RandomAccessFileOrArray(String filename, boolean forceRead, boolean plainRandomAccess) throws IOException {
      this(new RandomAccessSourceFactory()
        .setForceRead(forceRead)
        .setUsePlainRandomAccess(plainRandomAccess)
        .createBestSource(filename));
    }
View Full Code Here

     * @throws IOException
     * @deprecated use {@link RandomAccessSourceFactory#createSource(URL)} and {@link RandomAccessFileOrArray#RandomAccessFileOrArray(RandomAccessSource)} instead
     */
    @Deprecated
    public RandomAccessFileOrArray(URL url) throws IOException {
      this (new RandomAccessSourceFactory().createSource(url));
    }
View Full Code Here

     * @throws IOException
     * @deprecated use {@link RandomAccessSourceFactory#createSource(InputStream)} and {@link RandomAccessFileOrArray#RandomAccessFileOrArray(RandomAccessSource)} instead
     */
    @Deprecated
    public RandomAccessFileOrArray(InputStream is) throws IOException {
      this (new RandomAccessSourceFactory().createSource(is));
    }
View Full Code Here

     * @throws IOException
     * @deprecated use {@link RandomAccessSourceFactory#createSource(byte[])} and {@link RandomAccessFileOrArray#RandomAccessFileOrArray(RandomAccessSource)} instead
     */
   @Deprecated
    public RandomAccessFileOrArray(byte arrayIn[]) {
      this (new RandomAccessSourceFactory().createSource(arrayIn));
    }
View Full Code Here

   * @throws IOException
   */
  public static Image getInstance(final URL url, boolean recoverFromImageError) throws BadElementException,
      MalformedURLException, IOException {
    InputStream is = null;
        RandomAccessSourceFactory randomAccessSourceFactory = new RandomAccessSourceFactory();

    try {
      is = url.openStream();
      int c1 = is.read();
      int c2 = is.read();
      int c3 = is.read();
      int c4 = is.read();
      // jbig2
      int c5 = is.read();
      int c6 = is.read();
      int c7 = is.read();
      int c8 = is.read();
      is.close();

      is = null;
      if (c1 == 'G' && c2 == 'I' && c3 == 'F') {
        GifImage gif = new GifImage(url);
        Image img = gif.getImage(1);
        return img;
      }
      if (c1 == 0xFF && c2 == 0xD8) {
        return new Jpeg(url);
      }
      if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) {
        return new Jpeg2000(url);
      }
      if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) {
        return new Jpeg2000(url);
      }
      if (c1 == PngImage.PNGID[0] && c2 == PngImage.PNGID[1]
          && c3 == PngImage.PNGID[2] && c4 == PngImage.PNGID[3]) {
        return PngImage.getImage(url);
      }
      if (c1 == 0xD7 && c2 == 0xCD) {
        return new ImgWMF(url);
      }
      if (c1 == 'B' && c2 == 'M') {
        return  BmpImage.getImage(url);
      }
      if (c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42
          || c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0) {
        RandomAccessFileOrArray ra = null;
        try {
          if (url.getProtocol().equals("file")) {
            String file = url.getFile();
                        file = Utilities.unEscapeURL(file);
            ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createBestSource(file));
          } else
            ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createSource(url));
          Image img = TiffImage.getTiffImage(ra, 1);
          img.url = url;
          return img;
        } catch (RuntimeException e ) {
                    if ( recoverFromImageError ) {
                        // reruns the getTiffImage() with several error recovering workarounds in place
                        // not guaranteed to work with every TIFF
                        Image img = TiffImage.getTiffImage(ra, recoverFromImageError, 1);
                        img.url = url;
                        return img;
                    }
                    throw e;
                } finally {
          if (ra != null)
            ra.close();
        }

      }
      if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' &&
          c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
        RandomAccessFileOrArray ra = null;
        try {
          if (url.getProtocol().equals("file")) {
            String file = url.getFile();
            file = Utilities.unEscapeURL(file);
                  ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createBestSource(file));
          } else
            ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createSource(url));
          Image img = JBIG2Image.getJbig2Image(ra, 1);
          img.url = url;
          return img;
        } finally {
            if (ra != null)
View Full Code Here

   * @throws IOException
   */
  public static Image getInstance(final byte imgb[], boolean recoverFromImageError) throws BadElementException,
      MalformedURLException, IOException {
    InputStream is = null;
        RandomAccessSourceFactory randomAccessSourceFactory = new RandomAccessSourceFactory();
    try {
      is = new java.io.ByteArrayInputStream(imgb);
      int c1 = is.read();
      int c2 = is.read();
      int c3 = is.read();
      int c4 = is.read();
      is.close();

      is = null;
      if (c1 == 'G' && c2 == 'I' && c3 == 'F') {
        GifImage gif = new GifImage(imgb);
        return gif.getImage(1);
      }
      if (c1 == 0xFF && c2 == 0xD8) {
        return new Jpeg(imgb);
      }
      if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) {
        return new Jpeg2000(imgb);
      }
      if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) {
        return new Jpeg2000(imgb);
      }
      if (c1 == PngImage.PNGID[0] && c2 == PngImage.PNGID[1]
          && c3 == PngImage.PNGID[2] && c4 == PngImage.PNGID[3]) {
        return PngImage.getImage(imgb);
      }
      if (c1 == 0xD7 && c2 == 0xCD) {
        return new ImgWMF(imgb);
      }
      if (c1 == 'B' && c2 == 'M') {
        return BmpImage.getImage(imgb);
      }
      if (c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42
          || c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0) {
        RandomAccessFileOrArray ra = null;
        try {
          ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createSource(imgb));
          Image img = TiffImage.getTiffImage(ra, 1);
                    if (img.getOriginalData() == null)
                        img.setOriginalData(imgb);
          return img;
        } catch ( RuntimeException e ) {
                    if ( recoverFromImageError ) {
                        // reruns the getTiffImage() with several error recovering workarounds in place
                        // not guaranteed to work with every TIFF
                        Image img = TiffImage.getTiffImage(ra, recoverFromImageError, 1);
                        if (img.getOriginalData() == null)
                            img.setOriginalData(imgb);
                        return img;
                    }
                    throw e;
                } finally {
          if (ra != null)
            ra.close();
        }

      }
      if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' ) {
        is = new java.io.ByteArrayInputStream(imgb);
        is.skip(4);
        int c5 = is.read();
        int c6 = is.read();
        int c7 = is.read();
        int c8 = is.read();
                is.close();
        if ( c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) {
          // a jbig2 file with a file header.  the header is the only way we know here.
          // embedded jbig2s don't have a header, have to create them by explicit use of Jbig2Image?
          // nkerr, 2008-12-05  see also the getInstance(URL)
          RandomAccessFileOrArray ra = null;
          try {
            ra = new RandomAccessFileOrArray(randomAccessSourceFactory.createSource(imgb));
            Image img = JBIG2Image.getJbig2Image(ra, 1);
            if (img.getOriginalData() == null)
              img.setOriginalData(imgb);
            return img;
          } finally {
View Full Code Here

     * @param resources    the resources that come with the content stream
     */
    public void processContent(byte[] contentBytes, PdfDictionary resources){
        this.resources.push(resources);
        try {
            PRTokeniser tokeniser = new PRTokeniser(new RandomAccessFileOrArray(new RandomAccessSourceFactory().createSource(contentBytes)));
            PdfContentParser ps = new PdfContentParser(tokeniser);
            ArrayList<PdfObject> operands = new ArrayList<PdfObject>();
            while (ps.parse(operands).size() > 0){
                PdfLiteral operator = (PdfLiteral)operands.get(operands.size()-1);
                if ("BI".equals(operator.toString())){
View Full Code Here

     * preClose(), getRangeStream() and close().
     * <p>
     * @return the document bytes that are hashable
     */
    public InputStream getRangeStream() throws IOException {
      RandomAccessSourceFactory fac = new RandomAccessSourceFactory();
        return new RASInputStream(fac.createRanged(getUnderlyingSource(), range));
    }
View Full Code Here

TOP

Related Classes of com.itextpdf.text.io.RandomAccessSourceFactory

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.