Ostermillerutil Java Utilities Size Limit Input Stream - com.Ostermiller.util Java Utilities

A stream filter that will read only a specified amount before closing.

Many Internet protocols and file types specify byte lengths for certain sections of data just prior to the section of data. Size Limit Input Stream provides a mechanism for the entire data to be opened as a stream, and then section of the data be parceled out to other handlers. The handler is easier to write because its mission is no longer "read from this stream and process the data, but be careful not to read more than 398 bytes", but rather "read all the data from this stream and process the data." Handlers that are easier to write have fewer bugs. This also allows handlers that know how to process a stream, but may not have been written with sub-streams in mind, to be re-purposed without a change to the handler code.

An example of a protocol for a Size Limit Input Stream would be appropriate is the HTTP 1.1 protocol. In the HTTP 1.1 protocol a header for the web page is sent that contains (among other things) the size of the document. The document is then sent, and the stream is left open for subsequent requests. An implementation of an HTTP 1.1 client might read the headers, determine the size, and then pass off the actual document handling to another class via a SizeLimitInputStream.


License

OstermillerUtil Java Utilities Copyright (c) 2001-2020 by Stephen Ostermiller and other contributors

The OstermillerUtils library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

License FAQs - Why GPL? How about the LGPL or something else?