Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
commons-io-2.6-sources.jar - Apache Commons IO
commons-io-2.6-sources.jar is the source JAR file for Apache Commons IO 2.6, which is a library of utilities to assist with developing IO functionality.
JAR File Size and Download Location:
JAR name: commons-io-2.6-sources.jar Target JDK version: 1.7 Dependency: None File size: 280,834 bytes Release date: 15-Oct-2017 Download: Apache Commons IO Website
✍: FYIcenter.com
⏎ org/apache/commons/io/input/BoundedInputStream.java
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.commons.io.input; import static org.apache.commons.io.IOUtils.EOF; import java.io.IOException; import java.io.InputStream; /** * This is a stream that will only supply bytes up to a certain length - if its * position goes above that, it will stop. * <p> * This is useful to wrap ServletInputStreams. The ServletInputStream will block * if you try to read content from it that isn't there, because it doesn't know * whether the content hasn't arrived yet or whether the content has finished. * So, one of these, initialized with the Content-length sent in the * ServletInputStream's header, will stop it blocking, providing it's been sent * with a correct content length. * * @since 2.0 */ public class BoundedInputStream extends InputStream { /** the wrapped input stream */ private final InputStream in; /** the max length to provide */ private final long max; /** the number of bytes already returned */ private long pos = 0; /** the marked position */ private long mark = EOF; /** flag if close should be propagated */ private boolean propagateClose = true; /** * Creates a new <code>BoundedInputStream</code> that wraps the given input * stream and limits it to a certain size. * * @param in The wrapped input stream * @param size The maximum number of bytes to return */ public BoundedInputStream(final InputStream in, final long size) { // Some badly designed methods - eg the servlet API - overload length // such that "-1" means stream finished this.max = size; this.in = in; } /** * Creates a new <code>BoundedInputStream</code> that wraps the given input * stream and is unlimited. * * @param in The wrapped input stream */ public BoundedInputStream(final InputStream in) { this(in, EOF); } /** * Invokes the delegate's <code>read()</code> method if * the current position is less than the limit. * @return the byte read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read() throws IOException { if (max >= 0 && pos >= max) { return EOF; } final int result = in.read(); pos++; return result; } /** * Invokes the delegate's <code>read(byte[])</code> method. * @param b the buffer to read the bytes into * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b) throws IOException { return this.read(b, 0, b.length); } /** * Invokes the delegate's <code>read(byte[], int, int)</code> method. * @param b the buffer to read the bytes into * @param off The start offset * @param len The number of bytes to read * @return the number of bytes read or -1 if the end of stream or * the limit has been reached. * @throws IOException if an I/O error occurs */ @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (max>=0 && pos>=max) { return EOF; } final long maxRead = max>=0 ? Math.min(len, max-pos) : len; final int bytesRead = in.read(b, off, (int)maxRead); if (bytesRead==EOF) { return EOF; } pos+=bytesRead; return bytesRead; } /** * Invokes the delegate's <code>skip(long)</code> method. * @param n the number of bytes to skip * @return the actual number of bytes skipped * @throws IOException if an I/O error occurs */ @Override public long skip(final long n) throws IOException { final long toSkip = max>=0 ? Math.min(n, max-pos) : n; final long skippedBytes = in.skip(toSkip); pos+=skippedBytes; return skippedBytes; } /** * {@inheritDoc} */ @Override public int available() throws IOException { if (max>=0 && pos>=max) { return 0; } return in.available(); } /** * Invokes the delegate's <code>toString()</code> method. * @return the delegate's <code>toString()</code> */ @Override public String toString() { return in.toString(); } /** * Invokes the delegate's <code>close()</code> method * if {@link #isPropagateClose()} is {@code true}. * @throws IOException if an I/O error occurs */ @Override public void close() throws IOException { if (propagateClose) { in.close(); } } /** * Invokes the delegate's <code>reset()</code> method. * @throws IOException if an I/O error occurs */ @Override public synchronized void reset() throws IOException { in.reset(); pos = mark; } /** * Invokes the delegate's <code>mark(int)</code> method. * @param readlimit read ahead limit */ @Override public synchronized void mark(final int readlimit) { in.mark(readlimit); mark = pos; } /** * Invokes the delegate's <code>markSupported()</code> method. * @return true if mark is supported, otherwise false */ @Override public boolean markSupported() { return in.markSupported(); } /** * Indicates whether the {@link #close()} method * should propagate to the underling {@link InputStream}. * * @return {@code true} if calling {@link #close()} * propagates to the <code>close()</code> method of the * underlying stream or {@code false} if it does not. */ public boolean isPropagateClose() { return propagateClose; } /** * Set whether the {@link #close()} method * should propagate to the underling {@link InputStream}. * * @param propagateClose {@code true} if calling * {@link #close()} propagates to the <code>close()</code> * method of the underlying stream or * {@code false} if it does not. */ public void setPropagateClose(final boolean propagateClose) { this.propagateClose = propagateClose; } }
⏎ org/apache/commons/io/input/BoundedInputStream.java
Or download all of them as a single archive file:
File name: commons-io-2.6-sources.jar File size: 280834 bytes Release date: 2017-10-05 Download
⇒ Download and Install commons-io-2.5-bin.zip
2020-12-09, 61866👍, 1💬
Popular Posts:
itextpdf.jar is a component in iText 5 Java library to provide core functionalities. iText Java libr...
How to read XML document with XML Schema validation from socket connections with the socket\DelayedI...
Java Advanced Imaging (JAI) is a Java platform extension API that provides a set of object-oriented ...
What Is mail.jar of JavaMail 1.3? I got the JAR file from javamail-1_3.zip. mail.jar in javamail-1_3...
JDK 11 jdk.hotspot.agent.jmod is the JMOD file for JDK 11 Hotspot Agent module. JDK 11 Hotspot Agent...