Esempio n. 1
0
 PageSmoother(String pdf) throws IOException {
   File file = new File(pdf);
   ndone = 0;
   RandomAccessFile raf = new RandomAccessFile(file, "r");
   FileChannel channel = raf.getChannel();
   ByteBuffer buf = channel.map(FileChannel.MapMode.READ_ONLY, 0, channel.size());
   pdffile = new PDFFile(buf);
   page1 = new CountDownLatch(1);
   raf.close();
   tmpdir = File.createTempFile("pagesmoother", "");
   tmpdir.delete();
   tmpdir.mkdir();
 }
  private void readPalette() {
    RandomAccessFile rIn = null;
    ByteBuffer buf = null;
    int i;
    try {
      if (paletteFile != null) {
        // see if the file exists, if not, set it to the default palette.
        File file = new File(paletteFile);

        numPaletteEntries = (int) (file.length() / 4);

        buf = ByteBuffer.allocate(numPaletteEntries * 4);

        rIn = new RandomAccessFile(paletteFile, "r");

        FileChannel inChannel = rIn.getChannel();

        inChannel.position(0);
        inChannel.read(buf);

        // Check the byte order.
        buf.order(ByteOrder.LITTLE_ENDIAN);

        buf.rewind();
        IntBuffer ib = buf.asIntBuffer();
        paletteData = new int[numPaletteEntries];
        ib.get(paletteData);
        ib = null;
      }

    } catch (Exception e) {
      System.err.println("Caught exception: " + e.toString());
      System.err.println(e.getStackTrace());
    } finally {
      if (rIn != null) {
        try {
          rIn.close();
        } catch (Exception e) {
        }
      }
    }
  }