@Override public synchronized void reset() throws IOException { if (!in.markSupported()) { throw new IOException("Mark not supported"); } if (mark == -1) { throw new IOException("Mark not set"); } in.reset(); count = mark; } }
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); } } }
fInputStream.mark(kBufSize); byte[] inputBytes = new byte[kBufSize]; // Always make a new buffer because the bytesRead = IOUtils.readFully(fInputStream, inputBytes); if (bytesRead >= Integer.MAX_VALUE) { throw new IOException("Can't have read > Integer.MAX_VALUE bytes"); fInputStream.reset();
InputStream is = new BufferedInputStream(conn.getInputStream()); is.mark(is.available()); // Do the bound decoding // inJustDecodeBounds =true is.reset(); // Do the actual decoding
if (! stream.markSupported()) { stream = new BufferedInputStream(stream); stream.reset(); TikaInputStream tstream = TikaInputStream.get(stream, tmp);
/** 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; }
protected InputStream resetStream(InputStream imageStream, ImageDecodingInfo decodingInfo) throws IOException { if (imageStream.markSupported()) { try { imageStream.reset(); return imageStream; } catch (IOException ignored) { } } IoUtils.closeSilently(imageStream); return getImageStream(decodingInfo); }
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; }
@Override public synchronized void reset() throws IOException { if (!in.markSupported()) { throw new IOException("Mark not supported"); } if (mark == -1) { throw new IOException("Mark not set"); } in.reset(); left = mark; }
if (in instanceof BufferedInputStream) { in.mark(LOOKAHEAD_SIZE); long timeout = socket.getReadTimeout(); socket.setReadTimeout(HASH_READ_TIMEOUT); in.reset(); } else { } else { throw new IOException("Peer wants another torrent (" + Base64.encode(peerInfoHash) + ") while we only support (" + Base64.encode(coordinator.getInfoHash()) + ")"); throw new IOException("Peer wants another torrent (" + Base64.encode(peerInfoHash) + ") while we don't support that hash");
InputStream data = new BufferedInputStream(realResponse.getEntity().getContent()); // data.markSupported() should return "true" now data.mark(some_size); // work with "data" now ... data.reset();
/** * 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; } }
/** * Used to perform a last reset on the content input stream (if mark-supported); this is so * that, for backward compatibility reason, any "blind" retry (ie without calling reset) by * user of this library with the same input stream (such as ByteArrayInputStream) could * still succeed. * * @param t the failure * @return the failure as given */ private <T extends Throwable> T lastReset(final T t) { try { InputStream content = request.getContent(); if (content != null) { if (content.markSupported()) { content.reset(); } } } catch (Exception ex) { log.debug("FYI: failed to reset content inputstream before throwing up", ex); } return t; }
public void testLimit_skip() throws Exception { byte[] big = newPreFilledByteArray(5); InputStream bin = new ByteArrayInputStream(big); InputStream lin = ByteStreams.limit(bin, 2); // also test available lin.mark(2); assertEquals(2, lin.available()); lin.skip(1); assertEquals(1, lin.available()); lin.reset(); assertEquals(2, lin.available()); lin.skip(3); assertEquals(0, lin.available()); }
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; }
@Override public synchronized void reset() throws IOException { if (!in.markSupported()) { throw new IOException("Mark not supported"); } if (mark == -1) { throw new IOException("Mark not set"); } in.reset(); count = mark; } }