public void mark(int len) throws IOException { if (!input.markSupported()) { throw new IOException("Mark not supported for input stream " + input.getClass()); } input.mark(len); }
public EmptyBodyCheckingHttpInputMessage(HttpInputMessage inputMessage) throws IOException { this.headers = inputMessage.getHeaders(); InputStream inputStream = inputMessage.getBody(); if (inputStream.markSupported()) { inputStream.mark(1); this.body = (inputStream.read() != -1 ? inputStream : null); inputStream.reset(); } else { PushbackInputStream pushbackInputStream = new PushbackInputStream(inputStream); int b = pushbackInputStream.read(); if (b == -1) { this.body = null; } else { this.body = pushbackInputStream; pushbackInputStream.unread(b); } } }
InputStream is = new BufferedInputStream(conn.getInputStream()); is.mark(is.available()); // Do the bound decoding // inJustDecodeBounds =true is.reset(); // Do the actual decoding
InputStream bufIn = is.markSupported() ? is : new BufferedInputStream(is); bufIn.mark(4); DataInputStream in = new DataInputStream(bufIn); int magic = in.readInt();
/** Returns the ImageType for the given InputStream. */ @NonNull public static ImageType getType(@NonNull List<ImageHeaderParser> parsers, @Nullable InputStream is, @NonNull ArrayPool byteArrayPool) throws IOException { if (is == null) { return ImageType.UNKNOWN; } if (!is.markSupported()) { is = new RecyclableBufferedInputStream(is, byteArrayPool); } is.mark(MARK_POSITION); //noinspection ForLoopReplaceableByForEach to improve perf for (int i = 0, size = parsers.size(); i < size; i++) { ImageHeaderParser parser = parsers.get(i); try { ImageType type = parser.getType(is); if (type != ImageType.UNKNOWN) { return type; } } finally { is.reset(); } } return ImageType.UNKNOWN; }
InputStream is = null; try { is = new BufferedInputStream(new FileInputStream(new File(getCacheDir(), "mygif.gif")), 16 * 1024); is.mark(16 * 1024); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } movie = Movie.decodeStream(is);
InputStream logInboundEntity(final StringBuilder b, InputStream stream, final Charset charset) throws IOException { if (!stream.markSupported()) { stream = new BufferedInputStream(stream); } stream.mark(maxEntitySize + 1); final byte[] entity = new byte[maxEntitySize + 1]; final int entitySize = stream.read(entity); b.append(new String(entity, 0, Math.min(entitySize, maxEntitySize), charset)); if (entitySize > maxEntitySize) { b.append("...more..."); } b.append('\n'); stream.reset(); return stream; }
final InputStream bufferedInStream = new BufferedInputStream(fis); final String serializationName; try { bufferedInStream.mark(4096); final InputStream in = filename.endsWith(".gz") ? new GZIPInputStream(bufferedInStream) : bufferedInStream; final DataInputStream dis = new DataInputStream(in); serializationName = dis.readUTF(); bufferedInStream.reset(); } catch (final EOFException eof) { fis.close();
/** * Returns the orientation for the given InputStream. */ public static int getOrientation(@NonNull List<ImageHeaderParser> parsers, @Nullable InputStream is, @NonNull ArrayPool byteArrayPool) throws IOException { if (is == null) { return ImageHeaderParser.UNKNOWN_ORIENTATION; } if (!is.markSupported()) { is = new RecyclableBufferedInputStream(is, byteArrayPool); } is.mark(MARK_POSITION); //noinspection ForLoopReplaceableByForEach to improve perf for (int i = 0, size = parsers.size(); i < size; i++) { ImageHeaderParser parser = parsers.get(i); try { int orientation = parser.getOrientation(is, byteArrayPool); if (orientation != ImageHeaderParser.UNKNOWN_ORIENTATION) { return orientation; } } finally { is.reset(); } } return ImageHeaderParser.UNKNOWN_ORIENTATION; } }
/** * Return an InputStream that reads from the provided InputStream, decompresses the data * and returns a new InputStream wrapping the underlying payload. * * Note that src is modified by this call. * * @return * New Input stream with the underlying payload. * @throws Exception */ public static InputStream fromInputStream(InputStream src, StatsLogger statsLogger) throws IOException { src.mark(VERSION_LENGTH); byte version = new DataInputStream(src).readByte(); src.reset(); EnvelopedEntry entry = new EnvelopedEntry(version, statsLogger); entry.readFully(new DataInputStream(src)); return new ByteArrayInputStream(entry.getDecompressedPayload()); }
public InputStreamByteIterator(InputStream ins, long len) { this.len = len; this.ins = ins; off = 0; resetable = ins.markSupported(); if (resetable) { ins.mark((int) len); } }
InputStream logInboundEntity(final StringBuilder b, InputStream stream, final Charset charset) throws IOException { if (!stream.markSupported()) { stream = new BufferedInputStream(stream); } stream.mark(maxEntitySize + 1); final byte[] entity = new byte[maxEntitySize + 1]; final int entitySize = stream.read(entity); b.append(new String(entity, 0, Math.min(entitySize, maxEntitySize), charset)); if (entitySize > maxEntitySize) { b.append("...more..."); } b.append('\n'); stream.reset(); return stream; }
InputStream data = new BufferedInputStream(realResponse.getEntity().getContent()); // data.markSupported() should return "true" now data.mark(some_size); // work with "data" now ... data.reset();
@SuppressFBWarnings("OS_OPEN_STREAM") public static String getXMLType(@WillNotClose InputStream in) throws IOException { if (!in.markSupported()) { throw new IllegalArgumentException("Input stream does not support mark"); } in.mark(5000); BufferedReader r = null; try { r = new BufferedReader(Util.getReader(in), 2000); String s; int count = 0; while (count < 4) { s = r.readLine(); if (s == null) { break; } Matcher m = tag.matcher(s); if (m.find()) { return m.group(1); } } throw new IOException("Didn't find xml tag"); } finally { in.reset(); } }
private static Bitmap decodeStream(InputStream is, BitmapFactory.Options options, DecodeCallbacks callbacks, BitmapPool bitmapPool) throws IOException { if (options.inJustDecodeBounds) { is.mark(MARK_POSITION); } else { is.reset(); bitmapPool.put(options.inBitmap); options.inBitmap = null; is.reset();
/** * The readlimit parameter is ignored. */ @Override public void mark(int readlimit) { abortIfNeeded(); if ( !isAtStart ) throw new UnsupportedOperationException("Chunk-encoded stream only supports mark() at the start of the stream."); if (is.markSupported()) { if (log.isDebugEnabled()) { log.debug("AwsChunkedEncodingInputStream marked at the start of the stream " + "(will directly mark the wrapped stream since it's mark-supported)."); } is.mark(readlimit); } else { if (log.isDebugEnabled()) { log.debug("AwsChunkedEncodingInputStream marked at the start of the stream " + "(initializing the buffer since the wrapped stream is not mark-supported)."); } decodedStreamBuffer = new DecodedStreamBuffer(maxBufferSize); } }