Package java.io

Examples of java.io.DataInput


     */
    @Test
    @DependsOnMethod("testGetAsDataInputFromStream")
    public void testGetAsTemporaryByteBuffer() throws DataStoreException, IOException {
        StorageConnector connection = create(true);
        final DataInput in = ImageIO.createImageInputStream(connection.getStorage());
        assertNotNull("ImageIO.createImageInputStream(InputStream)", in); // Sanity check.
        connection = new StorageConnector(in);
        assertSame(in, connection.getStorageAs(DataInput.class));

        final ByteBuffer buffer = connection.getStorageAs(ByteBuffer.class);
View Full Code Here


     */
    @Test
    @DependsOnMethod("testGetAsDataInputFromStream")
    public void testCloseAllExcept() throws DataStoreException, IOException {
        final StorageConnector connection = create(true);
        final DataInput input = connection.getStorageAs(DataInput.class);
        final ReadableByteChannel channel = ((ChannelImageInputStream) input).channel;
        assertTrue("channel.isOpen()", channel.isOpen());
        connection.closeAllExcept(input);
        assertTrue("channel.isOpen()", channel.isOpen());
        channel.close();
View Full Code Here

        return deserialize(buf, 0, buf.length);
    }

    public static List<IndexMaintainer> deserialize(byte[] buf, int offset, int length) {
        ByteArrayInputStream stream = new ByteArrayInputStream(buf, offset, length);
        DataInput input = new DataInputStream(stream);
        List<IndexMaintainer> maintainers = Collections.emptyList();
        try {
            int size = WritableUtils.readVInt(input);
            boolean isDataTableSalted = size < 0;
            size = Math.abs(size);
View Full Code Here

   * If neither of those has been given to this object, <code>null</code> is returned.
   * @return DataInput object or <code>null</code>
   */
  public DataInput getInputAsDataInput()
  {
    DataInput din = getDataInput();
    if (din != null)
    {
      return din;
    }
    RandomAccessFile raf = getRandomAccessFile();
View Full Code Here

*/
public class TIFFDecoderUncompressed extends TIFFDecoder
{
  public void decode() throws IOException
  {
    DataInput in = getInput();
    byte[] row = new byte[getBytesPerRow()];
    for (int y = getY1(); y <= getY2(); y++)
    {
      in.readFully(row);
      putBytes(row, 0, row.length);
    }
  }
View Full Code Here

    MissingParameterException,
    UnsupportedTypeException,
    WrongFileFormatException,
    WrongParameterException
  {
    DataInput in = getInputAsDataInput();
    if (in == null)
    {
      throw new MissingParameterException("InputStream / DataInput object is missing.");
    }
    int formMagic = in.readInt();
    if (formMagic != MAGIC_FORM)
    {
      throw new WrongFileFormatException("Cannot load image. The " +
        "input stream is not a valid IFF file (wrong magic byte " +
        "sequence).");
    }
    in.readInt(); // read and discard "file size" field
    type = in.readInt();
    if (type != MAGIC_ILBM && type != MAGIC_PBM)
    {
      throw new UnsupportedTypeException("Cannot load image. The " +
        "input stream is an IFF file, but not of type ILBM or PBM" +
        " (" + getChunkName(type) + ")");
    }
    PixelImage result = null;
    boolean hasBMHD = false;
    boolean hasCAMG = false;
    do
    {
      int magic = in.readInt();
      //System.out.println(chunkNameToString(magic));
      int size = in.readInt();
      // chunks must always have an even number of bytes
      if ((size & 1) == 1)
      {
        size++;
      }
      //System.out.println("Chunk " + getChunkName(magic) + ", size=" + size);
      switch(magic)
      {
        case(MAGIC_BMHD): // main header with width, height, bit depth
        {
          if (hasBMHD)
          {
            throw new InvalidFileStructureException("Error in " +
              "IFF file: more than one BMHD chunk.");
          }
          if (size != SIZE_BMHD)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The bitmap header chunk does not " +
              "have the expected size.");
          }
          // image resolution in pixels
          width = in.readShort();
          height = in.readShort();
          if (width < 1 || height < 1)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The IFF file's bitmap header " +
              "contains invalid width and height values: " +
              width + ", " + height);
          }
          // next four bytes don't matter
          in.skipBytes(4);
          // color depth, 1..8 or 24
          numPlanes = in.readByte();
          if ((numPlanes != 24) && (numPlanes < 1 || numPlanes > 8))
          {
            throw new UnsupportedTypeException("Cannot load " +
              "image, unsupported number of bits per pixel: " +
              numPlanes);
          }
          //System.out.println("\nnum planes=" + numPlanes);
          in.readByte(); // discard "masking" value
          // compression type, must be 0 or 1
          compression = in.readByte();
          if (compression != COMPRESSION_NONE &&
              compression != COMPRESSION_RLE)
          {
            throw new UnsupportedTypeException("Cannot load " +
              "image, unsupported compression type: " +
              compression);
          }
          //System.out.println(getCompressionName(compression));
          in.skipBytes(9);
          hasBMHD = true;
          break;
        }
        case(MAGIC_BODY):
        {
          if (!hasBMHD)
          {
            // width still has its initialization value -1; no
            // bitmap chunk was encountered
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: No bitmap header chunk " +
              "encountered before image body chunk.");
          }
          if (palette == null && (!rgb24))
          {
            // a missing color map is allowed only for truecolor images
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: No colormap chunk " +
              "encountered before image body chunk.");
          }
          result = loadImage(in);
          break;
        }
        case(MAGIC_CAMG):
        {
          if (hasCAMG)
          {
            throw new InvalidFileStructureException("Cannot load image. Error in " +
              "IFF input stream: More than one CAMG chunk.");
          }
          hasCAMG = true;
          if (size < 4)
          {
            throw new InvalidFileStructureException("Cannot load" +
              " image. CAMG must be at least four bytes large; " +
              "found: " + size);
          }
          camg = in.readInt();
          ham = (camg & 0x800) != 0;
          ehb = (camg & 0x80) != 0;
          //System.out.println("ham=" + ham);
          in.skipBytes(size - 4);
          break;
        }
        case(MAGIC_CMAP): // palette (color map)
        {
          if (palette != null)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. Error in IFF " +
              "input stream: More than one palette.");
          }
          if (size < 3 || (size % 3) != 0)
          {
            throw new InvalidFileStructureException("Cannot " +
              "load image. The size of the colormap is " +
              "invalid: " + size);
          }
          int numColors = size / 3;
          palette = new Palette(numColors, 255);
          for (int i = 0; i < numColors; i++)
          {
            palette.putSample(Palette.INDEX_RED, i, in.readByte() & 0xff);
            palette.putSample(Palette.INDEX_GREEN, i, in.readByte() & 0xff);
            palette.putSample(Palette.INDEX_BLUE, i, in.readByte() & 0xff);
          }
          break;
        }
        default:
        {
          if (in.skipBytes(size) != size)
          {
            throw new IOException("Error skipping " + size +
              " bytes of input stream.");
          }
          break;
View Full Code Here

{
  public void decode() throws
    InvalidFileStructureException,
    IOException
  {
    DataInput in = getInput();
    byte[] row = new byte[getBytesPerRow()];
    for (int y = getY1(); y <= getY2(); y++)
    {
      int index = 0;
      do
      {
        byte value = in.readByte();
        if (value >= 0)
        {
          int numSamples = value + 1;
          // copy bytes literally
          in.readFully(row, index, numSamples);
          index += numSamples;
        }
        else
        if (value != (byte)-128)
        {
          int numSamples = - value + 1;
          // write run
          byte sample = in.readByte();
          while (numSamples-- != 0)
          {
            row[index++] = sample;
          }
        }
View Full Code Here

    IOException,
    OperationFailedException,
    UnsupportedTypeException,
    WrongFileFormatException
  {
    DataInput in = getInputAsDataInput();
    loadHeader(in);
    loadPalette(in);
    loadImage(in);
  }
View Full Code Here

    DataOutput output = new DataOutputStream(outputStream);
    messageBundle.write(output);

    ByteArrayInputStream inStream = new ByteArrayInputStream(
        outputStream.toByteArray());
    DataInput in = new DataInputStream(inStream);
    WritableMessageBundle<Writable> newBundle = new WritableMessageBundle<Writable>();
    newBundle.readFields(in);

    for (Writable writable : newBundle) {
      set.remove(writable);
View Full Code Here

      }
    } else { // size
      byte[] compressed = new byte[sizeOrVersion];
      in.readFully(compressed, 0, compressed.length);
      ByteArrayInputStream deflated = new ByteArrayInputStream(compressed);
      DataInput inflater =
        new DataInputStream(new InflaterInputStream(deflated));
      readFieldsCompressed(inflater);
    }
  }
View Full Code Here

TOP

Related Classes of java.io.DataInput

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.