Examples of BinaryInputStream


Examples of net.charabia.util.io.BinaryInputStream

    static public BufferedImage[] loadImages(File f) throws IOException
    {
  InputStream istream = new FileInputStream(f);
        BufferedInputStream buffin = new BufferedInputStream(istream);
  BinaryInputStream in = new BinaryInputStream(buffin);

  try {
      in.mark(1024 * 1024);

      IconDir dir = new IconDir(in);
      //      System.out.println("DIR = " + dir);

      IconEntry[] entries = new IconEntry[dir.idCount];
      BufferedImage[] images = new BufferedImage[dir.idCount];

      for (int i=0; i<dir.idCount; i++)
    {
        entries[i] = new IconEntry(in);
        //        System.out.println("ENTRY " + i + " = " + entries[i]);
    }

      IconEntry entry = entries[0];
      //      System.out.println("ENTRYx = " + entry);

      for (int i=0; i<dir.idCount; i++)
    {
        in.reset();

        boolean pngIcon = false;
        if (entries[i].dwBytesInRes > PNG_SIGNATURE.length) {
          //     Check if this is a PNG icon (introduced in Windows Vista)
          in.mark(1024 * 1024);
          in.skip(entries[i].dwImageOffset);
          byte[] signatureBuffer = new byte[PNG_SIGNATURE.length];
          in.read(signatureBuffer, 0, PNG_SIGNATURE.length);
          pngIcon = Arrays.equals(PNG_SIGNATURE, signatureBuffer);
          in.reset();
        }
        //    System.out.println("PNG Icon = " + pngIcon);

        in.skip(entries[i].dwImageOffset);

        BufferedImage image;

        if (pngIcon) {
          // This is a PNG icon (introduced in Windows Vista)
          byte[] imageData = new byte[(int) entries[i].dwBytesInRes];
          in.read(imageData, 0, (int) entries[i].dwBytesInRes);
          ByteArrayInputStream imageDataBuffer = new ByteArrayInputStream(imageData);
          image = ImageIO.read(imageDataBuffer);
        } else {
          //    This is a standard icon (not PNG)
          IconHeader header = new IconHeader(in);
          //        System.out.println("Header: " + header);

          long toskip = header.Size - 40;
          if (toskip>0)
        in.skip((int)toskip);

          //    System.out.println("skipped data");


          switch(header.BitsPerPixel)
View Full Code Here

Examples of org.apache.sanselan.common.BinaryInputStream

  public void setData(byte bytes[]) throws ImageReadException, IOException
  {
    data = bytes;

    BinaryInputStream bis = new BinaryInputStream(new ByteArrayInputStream(
        bytes), BYTE_ORDER_NETWORK);
    data_type_signature = bis.read4Bytes("data type signature",
        "ICC: corrupt tag data");

    itdt = getIccTagDataType(data_type_signature);
    //    if (itdt != null)
    //    {
View Full Code Here

Examples of org.apache.sanselan.common.BinaryInputStream

  public void setData(byte bytes[]) throws ImageReadException, IOException
  {
    data = bytes;

    BinaryInputStream bis = new BinaryInputStream(new ByteArrayInputStream(
        bytes), BYTE_ORDER_NETWORK);
    data_type_signature = bis.read4Bytes("data type signature",
        "ICC: corrupt tag data");

    itdt = getIccTagDataType(data_type_signature);
    //    if (itdt != null)
    //    {
View Full Code Here

Examples of org.apache.sanselan.common.BinaryInputStream

  protected List parseAllBlocks(byte bytes[], boolean verbose, boolean strict)
      throws ImageReadException, IOException
  {
    List blocks = new ArrayList();

    BinaryInputStream bis = new BinaryInputStream(bytes, APP13_BYTE_ORDER);

    // Note that these are unsigned quantities. Name is always an even
    // number of bytes (including the 1st byte, which is the size.)

    byte[] idString = bis.readByteArray(
        PHOTOSHOP_IDENTIFICATION_STRING.length,
        "App13 Segment missing identification string");
    if (!compareByteArrays(idString, PHOTOSHOP_IDENTIFICATION_STRING))
      throw new ImageReadException("Not a Photoshop App13 Segment");

    // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;

    while (true)
    {
      byte[] imageResourceBlockSignature = bis
          .readByteArray(CONST_8BIM.length,
              "App13 Segment missing identification string",
              false, false);
      if (null == imageResourceBlockSignature)
        break;
      if (!compareByteArrays(imageResourceBlockSignature, CONST_8BIM))
        throw new ImageReadException(
            "Invalid Image Resource Block Signature");

      int blockType = bis
          .read2ByteInteger("Image Resource Block missing type");
      if (verbose)
        Debug.debug("blockType", blockType + " (0x"
            + Integer.toHexString(blockType) + ")");

      int blockNameLength = bis
          .read1ByteInteger("Image Resource Block missing name length");
      if (verbose && blockNameLength > 0)
        Debug.debug("blockNameLength", blockNameLength + " (0x"
            + Integer.toHexString(blockNameLength) + ")");
      byte[] blockNameBytes;
      if (blockNameLength == 0)
      {
        bis.read1ByteInteger("Image Resource Block has invalid name");
        blockNameBytes = new byte[0];
      } else
      {
        blockNameBytes = bis.readByteArray(blockNameLength,
            "Invalid Image Resource Block name", verbose, strict);
        if (null == blockNameBytes)
          break;

        if (blockNameLength % 2 == 0)
          bis
              .read1ByteInteger("Image Resource Block missing padding byte");
      }

      int blockSize = bis
          .read4ByteInteger("Image Resource Block missing size");
      if (verbose)
        Debug.debug("blockSize", blockSize + " (0x"
            + Integer.toHexString(blockSize) + ")");

      byte[] blockData = bis.readByteArray(blockSize,
          "Invalid Image Resource Block data", verbose, strict);
      if (null == blockData)
        break;

      blocks.add(new IPTCBlock(blockType, blockNameBytes, blockData));

      if ((blockSize % 2) != 0)
        bis
            .read1ByteInteger("Image Resource Block missing padding byte");
    }

    return blocks;
  }
View Full Code Here

Examples of org.apache.sanselan.common.BinaryInputStream

    public void setData(byte bytes[]) throws ImageReadException, IOException
    {
        data = bytes;

        BinaryInputStream bis = new BinaryInputStream(new ByteArrayInputStream(
                bytes), BYTE_ORDER_NETWORK);
        data_type_signature = bis.read4Bytes("data type signature",
                "ICC: corrupt tag data");

        itdt = getIccTagDataType(data_type_signature);
        //        if (itdt != null)
        //        {
View Full Code Here

Examples of org.apache.sanselan.common.BinaryInputStream

    protected List parseAllBlocks(byte bytes[], boolean verbose, boolean strict)
            throws ImageReadException, IOException
    {
        List blocks = new ArrayList();

        BinaryInputStream bis = new BinaryInputStream(bytes, APP13_BYTE_ORDER);

        // Note that these are unsigned quantities. Name is always an even
        // number of bytes (including the 1st byte, which is the size.)

        byte[] idString = bis.readByteArray(
                PHOTOSHOP_IDENTIFICATION_STRING.length,
                "App13 Segment missing identification string");
        if (!compareByteArrays(idString, PHOTOSHOP_IDENTIFICATION_STRING))
            throw new ImageReadException("Not a Photoshop App13 Segment");

        // int index = PHOTOSHOP_IDENTIFICATION_STRING.length;

        while (true)
        {
            byte[] imageResourceBlockSignature = bis
                    .readByteArray(CONST_8BIM.length,
                            "App13 Segment missing identification string",
                            false, false);
            if (null == imageResourceBlockSignature)
                break;
            if (!compareByteArrays(imageResourceBlockSignature, CONST_8BIM))
                throw new ImageReadException(
                        "Invalid Image Resource Block Signature");

            int blockType = bis
                    .read2ByteInteger("Image Resource Block missing type");
            if (verbose)
                Debug.debug("blockType", blockType + " (0x"
                        + Integer.toHexString(blockType) + ")");

            int blockNameLength = bis
                    .read1ByteInteger("Image Resource Block missing name length");
            if (verbose && blockNameLength > 0)
                Debug.debug("blockNameLength", blockNameLength + " (0x"
                        + Integer.toHexString(blockNameLength) + ")");
            byte[] blockNameBytes;
            if (blockNameLength == 0)
            {
                bis.read1ByteInteger("Image Resource Block has invalid name");
                blockNameBytes = new byte[0];
            } else
            {
                blockNameBytes = bis.readByteArray(blockNameLength,
                        "Invalid Image Resource Block name", verbose, strict);
                if (null == blockNameBytes)
                    break;

                if (blockNameLength % 2 == 0)
                    bis
                            .read1ByteInteger("Image Resource Block missing padding byte");
            }

            int blockSize = bis
                    .read4ByteInteger("Image Resource Block missing size");
            if (verbose)
                Debug.debug("blockSize", blockSize + " (0x"
                        + Integer.toHexString(blockSize) + ")");

            /*
             * doesn't catch cases where blocksize is invalid but is still less than bytes.length
             * but will at least prevent OutOfMemory errors
             */
            if(blockSize > bytes.length) {
                throw new ImageReadException("Invalid Block Size : "+blockSize+ " > "+bytes.length);
            }

            byte[] blockData = bis.readByteArray(blockSize,
                    "Invalid Image Resource Block data", verbose, strict);
            if (null == blockData)
                break;

            blocks.add(new IPTCBlock(blockType, blockNameBytes, blockData));

            if ((blockSize % 2) != 0)
                bis
                        .read1ByteInteger("Image Resource Block missing padding byte");
        }

        return blocks;
    }
View Full Code Here

Examples of org.math.io.stream.BinaryInputStream

            throw new IllegalArgumentException(ex.toString());
        }

        BufferedInputStream bis = new BufferedInputStream(fis);

        BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);

        return bs.readIntArray();
    }
View Full Code Here

Examples of org.math.io.stream.BinaryInputStream

            throw new IllegalArgumentException(ex.toString());
        }

        BufferedInputStream bis = new BufferedInputStream(fis);

        BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);

        return bs.readFloatArray();
    }
View Full Code Here

Examples of org.math.io.stream.BinaryInputStream

            throw new IllegalArgumentException(ex.toString());
        }

        BufferedInputStream bis = new BufferedInputStream(fis);

        BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);

        return bs.readDoubleArray();
    }
View Full Code Here

Examples of org.math.io.stream.BinaryInputStream

            throw new IllegalArgumentException(ex.toString());
        }

        BufferedInputStream bis = new BufferedInputStream(fis);

        BinaryInputStream bs = new BinaryInputStream(bis, bigEndian);

        return bs.readByteArray();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.