org.apache.commons.io.input

Class BoundedReader

  • All Implemented Interfaces:
    Closeable, AutoCloseable, Readable


    public class BoundedReaderextends Reader
    A reader that imposes a limit to the number of characters that can be read from an underlying reader, returning eof when this limit is reached -regardless of state of underlying reader.

    One use case is to avoid overrunning the readAheadLimit supplied to java.io.Reader#mark(int), since reading too many characters removes the ability to do a successful reset.

    Since:
    2.5
    • Field Summary

    • Constructor Summary

      Constructors 
      Constructor and Description
      BoundedReader(Reader target, int maxCharsFromTargetReader)
      Constructs a bounded reader
    • Constructor Detail

      • BoundedReader

        public BoundedReader(Reader target,             int maxCharsFromTargetReader)              throws IOException
        Constructs a bounded reader
        Parameters:
        target - The target stream that will be used
        maxCharsFromTargetReader - The maximum number of characters that can be read from target
        Throws:
        IOException - if mark fails
    • Method Detail

      • reset

        public void reset()           throws IOException
        Resets the target to the latest mark, @see java.io.Reader#reset()
        Overrides:
        reset in class Reader
        Throws:
        IOException - If an I/O error occurs while calling the underlying reader's reset method
      • mark

        public void mark(int readAheadLimit)          throws IOException
        marks the target stream, @see java.io.Reader#mark(int).
        Overrides:
        mark in class Reader
        Parameters:
        readAheadLimit - The number of characters that can be read while still retaining the ability to do #reset(). Note that this parameter is not validated with respect to maxCharsFromTargetReader. There is no way to pass past maxCharsFromTargetReader, even if this value is greater.
        Throws:
        IOException - If an I/O error occurs while calling the underlying reader's mark method
      • read

        public int read()         throws IOException
        Reads a single character, @see java.io.Reader#read()
        Overrides:
        read in class Reader
        Returns:
        -1 on eof or the character read
        Throws:
        IOException - If an I/O error occurs while calling the underlying reader's read method
      • read

        public int read(char[] cbuf,       int off,       int len)         throws IOException
        Reads into an array, @see java.io.Reader#read(char[], int, int)
        Specified by:
        read in class Reader
        Parameters:
        cbuf - The buffer to fill
        off - The offset
        len - The number of chars to read
        Returns:
        the number of chars read
        Throws:
        IOException - If an I/O error occurs while calling the underlying reader's read method

Copyright © 2002–2016 The Apache Software Foundation. All rights reserved.



NOTHING
NOTHING
Add the Maven Dependecy to your project: maven dependecy for com.amazonaws : aws-java-sdk : 1.3.14