Documentation of 'org.freehep.util.io.RoutedInputStream' Java class
RoutedInputStream
org.freehep.util.io

Class RoutedInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable
    Direct Known Subclasses:
    PromptInputStream


    public class RoutedInputStream
    extends java.io.InputStream
    The RoutedInputStream allows the user to add a listener for a certain delimited portion of the main inputstream. This portion is marked by a start and end marker. The end marker can be null, in which case the portion runs from the start marker to the end of the main inputstream. The listener is informed via a route (partial inputstream) when input is available. The new routed inputstream (route) is supposed to be read to the end or closed, after which the main inputstream should be read again. Closing a route will not close the original stream, but will discard any bytes up to and including the end marker. Returning from a route without reading until the end of the route means that the remaining bytes are still available on the main stream. Multiple routes can be added, as long as they have different start sequences. Start sequences such as "StartA, StartB, StartEmpty" are allowed, but "Start, StartOther" are not since they overlap. Start and End markers can be the same. IMPORTANT: inherits from InputStream rather than FilterInputStream so that the correct read(byte[], int, int) method is used.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      class  RoutedInputStream.Route
      Route which can be read up to and including the end marker.
    • Constructor Summary

      Constructors 
      Constructor and Description
      RoutedInputStream(java.io.InputStream input)
      Creates a RoutedInputStream from the underlying stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      void addRoute(byte[] start, byte[] end, RouteListener listener)
      Adds a route for given start and end marker.
      void addRoute(java.lang.String start, java.lang.String end, RouteListener listener)
      Adds a route for given start and end string.
      int read()
      Returns the next byte on this stream, however if a start marker is found, the associated route listener is called, which should take over reading the stream.
      • Methods inherited from class java.io.InputStream

        available, close, mark, markSupported, read, read, reset, skip
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • RoutedInputStream

        public RoutedInputStream(java.io.InputStream input)
        Creates a RoutedInputStream from the underlying stream.
        Parameters:
        input - stream to read
    • Method Detail

      • read

        public int read()
                 throws java.io.IOException
        Returns the next byte on this stream, however if a start marker is found, the associated route listener is called, which should take over reading the stream. In this case this method will, after the route is finished reading and closed, return the first byte after the end marker. This of course unless that byte is part of the next start marker.
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • addRoute

        public void addRoute(java.lang.String start,
                             java.lang.String end,
                             RouteListener listener)
        Adds a route for given start and end string. The strings are converted according to the default encoding to start and end markers (byte[]).
        Parameters:
        start - start marker
        end - end marker
        listener - listener to inform about the route
      • addRoute

        public void addRoute(byte[] start,
                             byte[] end,
                             RouteListener listener)
        Adds a route for given start and end marker. If the end marker is null, the route is indefinite, and can be read until the main stream ends. If the start and end marker are equal, the route can be read for exactly their length.
        Parameters:
        start - start marker
        end - end marker
        listener - listener to inform about the route

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.