Positions the given input stream to the beginning of the EXIF data in the JPEG APP1 block.
@param is the input stream of jpeg image
@return length of EXIF data
546775
private static int moveToAPP1EXIF(InputStream is) throws IOException {
    if (moveToMarker(is, MARKER_APP1)) {
      // read block length
      // subtract 2 as length contain SIZE field we just read
      int length = StreamProcessor.readPackedInt(is, 2, false) - 2;
      if (length > 6) {
        int magic = StreamProcessor.readPackedInt(is, 4, false);
        length -= 4;
        int zero = StreamProcessor.readPackedInt(is, 2, false);
        length -= 2;
        if (magic == APP1_EXIF_MAGIC && zero == 0) {
          // JEITA CP-3451 Exif Version 2.2
          return length;
        }
      }
    }
    return 0;
  }
1249633
public static byte[] readBytesFromOtherInputStream(InputStream is) throws IOException
    {
        ByteArrayOutputStream data = new ByteArrayOutputStream();

        int readBytes;
        byte[] buffer = new byte[Math.max(is.available(), 4096)]; // 最低4KB的缓冲区

        while ((readBytes = is.read(buffer, 0, buffer.length)) != -1)
        {
            data.write(buffer, 0, readBytes);
        }

        data.flush();

        return data.toByteArray();
    }
165361
def _tiff_from_exif_segment(cls, stream, offset, segment_length):
        
        # wrap full segment in its own stream and feed to Tiff()
        stream.seek(offset+8)
        segment_bytes = stream.read(segment_length-8)
        substream = BytesIO(segment_bytes)
        return Tiff.from_stream(substream)
234407
static private long skipForward(InputStream is, long toSkip)
                throws IOException {

        long eachSkip = 0;
        long skipped = 0;

        while (skipped != toSkip) {
            eachSkip = is.skip(toSkip - skipped);

            // check if EOF is reached
            if (eachSkip <= 0) {
                if (is.read() == -1) {
                    return skipped ;
                } else {
                    skipped++;
                }
            }
            skipped += eachSkip;
        }
        return skipped;
    }
380629
public static int readBytesFromOtherInputStream(InputStream is, byte[] targetArray) throws IOException
    {
        assert targetArray != null;
        if (targetArray.length == 0) return 0;
        int len;
        int off = 0;
        while (off < targetArray.length && (len = is.read(targetArray, off, targetArray.length - off)) != -1)
        {
            off += len;
        }
        return off;
    }
1264505
public static ByteBuffer getByteBufferFromInputStreamAndCloseStream(InputStream is) throws IOException {
        try {
            // is.available() may return 0, or 1, or the total number of bytes in the stream,
            // or some other number.
            // Do not try to use is.available() == 0 to find the end of the stream!
            byte[] bytes;
            int avail = is.available();
            if (avail > 32) {
                // There are more bytes available than just the ICU data header length.
                // With luck, it is the total number of bytes.
                bytes = new byte[avail];
            } else {
                bytes = new byte[128];  // empty .res files are even smaller
            }
            // Call is.read(...) until one returns a negative value.
            int length = 0;
            for(;;) {
                if (length < bytes.length) {
                    int numRead = is.read(bytes, length, bytes.length - length);
                    if (numRead < 0) {
                        break;  // end of stream
                    }
                    length += numRead;
                } else {
                    // See if we are at the end of the stream before we grow the array.
                    int nextByte = is.read();
                    if (nextByte < 0) {
                        break;
                    }
                    int capacity = 2 * bytes.length;
                    if (capacity < 128) {
                        capacity = 128;
                    } else if (capacity < 0x4000) {
                        capacity *= 2;  // Grow faster until we reach 16kB.
                    }
                    // TODO Java 6 replace new byte[] and arraycopy(): bytes = Arrays.copyOf(bytes, capacity);
                    byte[] newBytes = new byte[capacity];
                    System.arraycopy(bytes, 0, newBytes, 0, length);
                    bytes = newBytes;
                    bytes[length++] = (byte) nextByte;
                }
            }
            return ByteBuffer.wrap(bytes, 0, length);
        } finally {
            is.close();
        }
    }
323997
private static int getTrimmedXStart(BufferedImage img) {
    int height = img.getHeight();
    int width = img.getWidth();
    int xStart = width;

    for (int i = 0; i < height; i++) {
      for (int j = 0; j < width; j++) {
        if (img.getRGB(j, i) != Color.WHITE.getRGB() && j < xStart) {
          xStart = j;
          break;
        }
      }
    }

    return xStart;
  }
999454
public synchronized static Bitmap load(InputStream is, int width, int height) {
        BitmapFactory.Options opt = null;
        try {
            opt = new BitmapFactory.Options();
            if (width > 0 && height > 0) {
                if (is.markSupported()) {
                    is.mark(is.available());

                    opt.inJustDecodeBounds = true;
                    BitmapFactory.decodeStream(is, null, opt);
                    opt.inSampleSize = calculateInSampleSize(opt, width, height);
                    is.reset();
                }
            }

            opt.inJustDecodeBounds = false;
            opt.inPurgeable = true;
            opt.inInputShareable = true;

            return BitmapFactory.decodeStream(new FlushedInputStream(is), null, opt);
        } catch (Exception e) {
            Log.e(TAG, "", e);
            return null;
        } finally {
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    System.out.print(e.toString());
                }
            }
            opt = null;
        }
    }
905589
static int getLength(int lenByte, InputStream in) throws IOException {
        int value, tmp;

        tmp = lenByte;
        if ((tmp & 0x080) == 0x00) { // short form, 1 byte datum
            value = tmp;
        } else {                     // long form or indefinite
            tmp &= 0x07f;

            /*
             * NOTE:  tmp == 0 indicates indefinite length encoded data.
             * tmp > 4 indicates more than 4Gb of data.
             */
            if (tmp == 0)
                return -1;
            if (tmp < 0 || tmp > 4)
                throw new IOException("DerInputStream.getLength(): lengthTag="
                    + tmp + ", "
                    + ((tmp < 0) ? "incorrect DER encoding." : "too big."));

            for (value = 0; tmp > 0; tmp --) {
                value <<= 8;
                value += 0x0ff & in.read();
            }
            if (value < 0) {
                throw new IOException("DerInputStream.getLength(): "
                        + "Invalid length bytes");
            }
        }
        return value;
    }
351135
private static int read(InputStream is) throws IOException {
        int b = is.read();
        if (b == -1) {
            throw new EOFException();
        }
        return b;
    }
556204
@Override
    public boolean hasNext(int startPosition, int contentLength) {
        byte b = readByte();
        if (b == SIGN_HASNEXT) return true;
        if (b != SIGN_NONEXT) throw new ConvertException("hasNext option must be (" + (SIGN_HASNEXT)
                + " or " + (SIGN_NONEXT) + ") but '" + b + "' at position(" + this.position + ")");
        return false;
    }
1088138
public static int lengthOfCodePointFromStartByte(byte startByte)
    {
        int unsignedStartByte = startByte & 0xFF;
        if (unsignedStartByte < 0x80) {
            // normal ASCII
            // 0xxx_xxxx
            return 1;
        }
        if (unsignedStartByte < 0xc0) {
            // illegal bytes
            // 10xx_xxxx
            throw new InvalidUtf8Exception("Illegal start 0x" + toHexString(unsignedStartByte).toUpperCase() + " of code point");
        }
        if (unsignedStartByte < 0xe0) {
            // 110x_xxxx 10xx_xxxx
            return 2;
        }
        if (unsignedStartByte < 0xf0) {
            // 1110_xxxx 10xx_xxxx 10xx_xxxx
            return 3;
        }
        if (unsignedStartByte < 0xf8) {
            // 1111_0xxx 10xx_xxxx 10xx_xxxx 10xx_xxxx
            return 4;
        }
        // Per RFC3629, UTF-8 is limited to 4 bytes, so more bytes are illegal
        throw new InvalidUtf8Exception("Illegal start 0x" + toHexString(unsignedStartByte).toUpperCase() + " of code point");
    }
868372
public static void readAndCloseStream(InputStream is) {
		final byte[] bytes = new byte[DEFAULT_BUFFER_SIZE];
		try {
			while (is.read(bytes, 0, DEFAULT_BUFFER_SIZE) != -1);
		} catch (IOException ignored) {
		} finally {
			closeSilently(is);
		}
	}
504443
public long getImageSize() {
    long x = 0, y = 0;
    if (tags.containsTagId(TiffTags.getTagId("ImageLength")))
      x = tags.get("ImageLength").getFirstNumericValue();
    if (tags.containsTagId(TiffTags.getTagId("ImageWidth")))
      y = tags.get("ImageWidth").getFirstNumericValue();
    return x * y;
  }
260078
ByteBuffer writeView(int position, int needs) throws IOException
    {
        int waterMark = position+needs;
        if (waterMark > content.capacity())
        {
            if (refSet.containsKey(content))
            {
                throw new IOException("cannot grow file because of writable mapping for content. (non carbage collected mapping?)");
            }
            int blockSize = fileStore.getBlockSize();
            int newCapacity = Math.max(((waterMark / blockSize) + 1) * blockSize, 2*content.capacity());
            ByteBuffer newBB = ByteBuffer.allocateDirect(newCapacity);
            newBB.put(content);
            newBB.flip();
            content = newBB;
        }
        ByteBuffer bb = content.duplicate();
        refSet.add(content, bb);
        bb.limit(waterMark).position(position);
        return bb;
    }
599471
@Override
    public long length()
                    throws IOException {
        int len = physical.size();
        int answer = 0;
        for (int i = 0; i < len; i++) {
            RandomAccessFile raf = (RandomAccessFile) physical.get(i);
            if (raf != null) {
                answer += raf.length();
            }
        }
        return answer;
    }
714521
private int readShort(InputStream is)
    throws IOException
  {
    int c1 = is.read();
    int c2 = is.read();

    return ((c1 << 8) | c2);
  }