/** Returns an input stream encapsulating a nonempty fragment of an array of input streams. * * @param inputStream an array of input streams, that will be encapsulated. * @param offset the first input stream that will be encapsulated. * @param length the number of input streams to be encapsulated. * @return an input stream encapsulating the argument streams (the only argument, if length is 1). */ public static InputStream getStream( final InputStream[] inputStream, final int offset, final int length ) { if ( length == 0 ) return NullInputStream.getInstance(); if ( length == 1 ) return inputStream[ offset ]; return new MultipleInputStream( inputStream, offset ,length ); }
private void safelyCloseDumpStream() { try { if ( this.dumpStream != null ) this.dumpStream.close(); } catch ( IOException ignore ) {} }
public void addOccurrence( int document, int position ) throws IOException { obs.writeDelta( document - lastDocument ); if ( document != lastDocument ) lastPosition = -1; obs.writeDelta( position - lastPosition - 1 ); lastDocument = document; lastPosition = position; } }
public int decode( final InputBitStream ibs ) throws IOException { Node n = root; while( ! ( n instanceof LeafNode ) ) n = ibs.readBit() == 0 ? n.left : n.right; return ((LeafNode)n).symbol; }
/** Creats a stream with one marker in. * * @param in the underlying input stream. * @param delimiter an array of segment delimiters. */ public SegmentedInputStream( final InputStream in, final long... delimiter ) throws NullPointerException, IOException, IllegalStateException { this( in ); addBlock( delimiter ); }
/** Returns an input stream encapsulating a nonempty array of input streams. * * <p>Note that if <code>inputStream.length</code> is 1 this method will return the only stream * that should be encapsulated. * * @param inputStream an array of input streams, that will be encapsulated. * @return an input stream encapsulating the argument streams (the only argument, if the length is 1). */ public static InputStream getStream( final InputStream[] inputStream ) { return getStream( inputStream, 0, inputStream.length ); }
@Override public int encode( final int symbol, final OutputBitStream obs ) throws IOException { return obs.writeLong( longCodeWord[ symbol ], length[ symbol ] ); } }
/** Checks if the current position is a stop marker. * * @return false if a skip has to be done or eof has been reached, true otherwise. */ private boolean eofInBlock() { ensureBlocksNotEmpty(); ensureNotClosed(); return relativePos >= segmentLen; }
/** Adds all the elements of the given iterable at the end of this iterable. * * @param it the iterable producing the elements to be added. * @throws IOException */ public void addAll( Iterable<T> it ) throws IOException { for ( T x: it ) add( x ); }
/** Aligns the stream. * * After a call to this method, the stream is byte aligned. Zeroes * are used to pad it if necessary. * * @return the number of padding bits. */ public int align() throws IOException { if ( free != 8 ) return writeInCurrent( 0, free ); else return 0; }
@Override public long length() throws IOException { ensureNotClosed(); return segmentLen; }
/** Adds a new element at the end of this iterable. * * @param x the element to be added. * @throws IOException */ public void add( T x ) throws IOException { serializer.write( x, dos ); size++; }
public int read() throws IOException { if ( noMoreCharacters() ) return -1; avail--; return buffer[ pos++ ]; }
/** Returns an input stream encapsulating a nonempty fragment of an array of input streams. * * @param inputStream an array of input streams, that will be encapsulated. * @param offset the first input stream that will be encapsulated. * @param length the number of input streams to be encapsulated. * @return an input stream encapsulating the argument streams (the only argument, if length is 1). */ public static InputStream getStream(final InputStream[] inputStream, final int offset, final int length) { if (length == 0) return NullInputStream.getInstance(); if (length == 1) return inputStream[offset]; return new MultipleInputStream(inputStream, offset ,length); }
/** Writes a bit. * * @param bit a bit. * @return the number of bits written. */ public int writeBit( final boolean bit ) throws IOException { return writeInCurrent( bit ? 1 : 0, 1 ); }
@Override public long position() throws IOException { ensureNotClosed(); return relativePos; }
/** Returns an input stream encapsulating a nonempty fragment of an array of input streams. * * @param inputStream an array of input streams, that will be encapsulated. * @param offset the first input stream that will be encapsulated. * @param length the number of input streams to be encapsulated. * @return an input stream encapsulating the argument streams (the only argument, if length is 1). */ public static InputStream getStream( final InputStream[] inputStream, final int offset, final int length ) { if ( length == 0 ) return NullInputStream.getInstance(); if ( length == 1 ) return inputStream[ offset ]; return new MultipleInputStream( inputStream, offset ,length ); }