Java 8 ImageInputStream - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ImageInputStream class.

This code example shows how to use the following methods:mark, read, reset, seek
    } 
 
    @Override 
    public boolean canDecodeInput(Object source) throws IOException {
        ImageInputStream markable = (ImageInputStream) source;
        markable.mark();
 
        byte[] signature = new byte[8];
        markable.seek(0);
 
        int nBytes = markable.read(signature, 0, 8);
        if(nBytes != 8) markable.read(signature, nBytes, 8-nBytes);
        markable.reset();
 
        // PNG signature: 137 80 78 71 13 10 26 10 
        return  (signature[0] & 0xFF) == 137 &&
                (signature[1] & 0xFF) == 80 &&
                (signature[2] & 0xFF) == 78 &&
                (signature[3] & 0xFF) == 71 &&
                (signature[4] & 0xFF) == 13 &&
7
CodeRank
This code example shows how to use the following methods:mark, read, reset, skipBytes
    } 
 
    @Override 
    public boolean canDecodeInput(Object source) throws IOException {
        ImageInputStream iis = (ImageInputStream) source;
        iis.mark();
        try { 
            int tag = iis.read()
                   | (iis.read()<<8)
                   | (iis.read()<<16)
                   | (iis.read()<<24);
            return ((tag >= 0x00080000 && tag <= 0x00080016)
                  || (iis.skipBytes(124) == 124
                   && iis.read() == 'D'
                   && iis.read() == 'I'
                   && iis.read() == 'C'
                   && iis.read() == 'M'));
        } finally { 
            iis.reset();
        } 

6
CodeRank
This code example shows how to use the following methods:getStreamPosition, writeBytes
public class CommonFileDescriptorRecordTest extends TestCase {
 
    public void testInitCommonFileDescriptorRecord() throws IOException,
                                                            IllegalCeosFormatException { 
        final ByteArrayOutputStream os = new ByteArrayOutputStream(24);
        final ImageOutputStream ios = new MemoryCacheImageOutputStream(os);
        final String prefix = "fdkjglsdkfhierr.m b9b0970w34";
        ios.writeBytes(prefix);
        writeRecordData(ios);
        ios.writeBytes("nq3tf9ß8nvnvpdi er 0 324p3f"); // as suffix
 
        final CommonFileDescriptorRecord record = new CommonFileDescriptorRecord(new CeosFileReader(ios),
                                                                                 prefix.length());
 
        assertRecord(record);
        assertEquals(prefix.length(), record.getStartPos());
        assertEquals(prefix.length() + 180, ios.getStreamPosition());
    } 
 
    public static void assertRecord(final CommonFileDescriptorRecord record) {

6
CodeRank
This code example shows how to use the following methods:close
			if (imageReader != null) {
				imageReader.dispose();
			} 
			if (imageInputStream != null) {
				try { 
					imageInputStream.close();
				} 
				catch (IOException ex) {
					// ignore 
				} 
			} 
		} 
	} 
 
	private ImageInputStream createImageInputStream(InputStream is) throws IOException {
		if (this.cacheDir != null) {
			return new FileCacheImageInputStream(is, cacheDir);
		} 
		else { 
			return new MemoryCacheImageInputStream(is);
6
CodeRank
This code example shows how to use the following methods:close, mark
					LOGGER.fine("Unable to get an ImageInputStream");
				return false; 
			} 
 
			// get a reader 
			if (!IMAGEIO_READER_FACTORY.canDecodeInput(inputStream))
				return false; 
			reader = IMAGEIO_READER_FACTORY.createReaderInstance();
			 
 
			inputStream.mark();
			reader.setInput(inputStream);
			final IIOMetadata metadata = reader.getImageMetadata(0);
			if(metadata==null)
				return false; 
			// 
			// parse metadata and be resilient with CRS 
			// 
			final GeoTiffIIOMetadataDecoder metadataAdapter = new GeoTiffIIOMetadataDecoder(metadata);
			if(!metadataAdapter.hasGeoKey()&& LOGGER.isLoggable(Level.FINE))

6
CodeRank
This code example shows how to use the following methods:mark, readShort, reset
 
  @Override 
  public boolean canDecodeInput(Object source) throws IOException {
    if (source instanceof ImageInputStream) {
      ImageInputStream in = (ImageInputStream) source;
      in.mark();
      // Check if file starts with a JFIF SOI magic (0xffd8=-40) 
      if (in.readShort() != -40) {
        in.reset();
        return false; 
      } 
      in.reset();
      return true; 
    } 
    return false; 
  } 
 
  @Override 
  public ImageReader createReaderInstance(Object extension) throws IOException {
    return new CMYKJPEGImageReader(this);
6
CodeRank
This code example shows how to use the following methods:skipBytes, writeBytes
 
    private void writeRecordData(final ImageOutputStream ios) throws IOException {
        BaseRecordTest.writeRecordData(ios);
 
        // codeCharacter = "A" + 1 blank 
        ios.writeBytes("A "); // A2
        ios.skipBytes(2); // reader.skipBytes(2);  // blank
        // productID = "PRODUCT:ABBBCCDE" + 24 blanks 
        ios.writeBytes("PRODUCT:O1B2R_UB                        "); // A40
        // facility = "PROCESS:JAPAN-JAXA-EOC-ALOS-DPS  YYYYMMDDHHNNSS" + 13 blanks 
        ios.writeBytes("PROCESS:JAPAN-JAXA-EOC-ALOS-DPS  20060410075225             "); //A60
        // sceneID =  "ORBIT:AABBBCDDDDDEEEE" + 19 blanks 
        ios.writeBytes("ORBIT:ALPSMB003062950                   "); // A40
        // imageFormat = "BSQ" + 1 blank 
        ios.writeBytes("BSQ "); // A4
        // Blank = 200 blanks 
        CeosTestHelper.writeBlanks(ios, 200);
    } 
 
    private void assertRecord(final TextRecord record) throws IOException {
6
CodeRank
This code example shows how to use the following methods:getStreamPosition, isCached, length
   * stream without blocking. 
   * @exception IOException if an I/O error occurs. 
   */ 
  @Override 
  public int available() throws IOException {
    return (iis.isCached()) ? //
      (int) Math.min(Integer.MAX_VALUE, iis.length() - iis.getStreamPosition())
      : 0; 
  } 
 
  /** 
   * Closes this input stream and releases any system resources associated with the stream. This 
   * method simply performs 
   * <code>in.close()</code>. 
   * 
   * @exception IOException if an I/O error occurs. 
   * @see java.io.FilterInputStream#in 
   */ 
  @Override 
  public void close() throws IOException {
6
CodeRank
This code example shows how to use the following methods:mark, read, reset, skipBytes
    } 
 
    @Override 
    public boolean canDecodeInput(Object source) throws IOException {
        ImageInputStream iis = (ImageInputStream) source;
        iis.mark();
        try { 
            int tag = iis.read()
                   | (iis.read()<<8)
                   | (iis.read()<<16)
                   | (iis.read()<<24);
            return ((tag >= 0x00080000 && tag <= 0x00080016)
                  || (iis.skipBytes(124) == 124
                   && iis.read() == 'D'
                   && iis.read() == 'I'
                   && iis.read() == 'C'
                   && iis.read() == 'M'));
        } finally { 
            iis.reset();
        } 

6
CodeRank
This code example shows how to use the following methods:mark, readShort, reset
 
    @Override 
    public boolean canDecodeInput(Object source) throws IOException {
        if (source instanceof ImageInputStream) {
            ImageInputStream in = (ImageInputStream) source;
            in.mark();
            // Check if file starts with a JFIF SOI magic (0xffd8=-40) 
            if (in.readShort() != -40) {
                in.reset();
                return false; 
            } 
            in.reset();
            return true; 
        } 
        return false; 
    } 
 
    @Override 
    public ImageReader createReaderInstance(Object extension) throws IOException {
        return new CMYKJPEGImageReader(this);
5
CodeRank
See Code Examples for Java 8 ImageInputStream Methods: