/** Reads a line into the given byte-array fragment using {@linkplain #ALL_TERMINATORS all terminators}. * * @param array byte array where the next line will be stored. * @param off the first byte to use in {@code array}. * @param len the maximum number of bytes to read. * @return the number of bytes actually placed in {@code array}, or -1 at end of file. * @see #readLine(byte[], int, int, EnumSet) */ public int readLine(final byte[] array, final int off, final int len) throws IOException { return readLine(array, off, len, ALL_TERMINATORS); }
/** Reads a line into the given byte array. * * @param array byte array where the next line will be stored. * @param terminators a set containing the line termination sequences that we want * to consider as valid. * @return the number of bytes actually placed in {@code array}, or -1 at end of file. * @see #readLine(byte[], int, int, EnumSet) */ public int readLine(final byte[] array, final EnumSet<LineTerminator> terminators) throws IOException { return readLine(array, 0, array.length, terminators); }
/** Reads a line into the given byte array using {@linkplain #ALL_TERMINATORS all terminators}. * * @param array byte array where the next line will be stored. * @return the number of bytes actually placed in {@code array}, or -1 at end of file. * @see #readLine(byte[], int, int, EnumSet) */ public int readLine(final byte[] array) throws IOException { return readLine(array, 0, array.length, ALL_TERMINATORS); }
private final int readLine( final FastBufferedInputStream fbis ) throws IOException { int start = 0, len; while( ( len = fbis.readLine( lineBuffer, start, lineBuffer.length - start, FastBufferedInputStream.ALL_TERMINATORS ) ) == lineBuffer.length - start ) { start += len; lineBuffer = ByteArrays.grow( lineBuffer, lineBuffer.length + 1 ); } if ( len != -1 ) start += len; return len == -1 ? -1 : start; }
private final int readLine( final FastBufferedInputStream fbis ) throws IOException { int start = 0, len; while( ( len = fbis.readLine( lineBuffer, start, lineBuffer.length - start, FastBufferedInputStream.ALL_TERMINATORS ) ) == lineBuffer.length - start ) { start += len; lineBuffer = ByteArrays.grow( lineBuffer, lineBuffer.length + 1 ); } if ( len != -1 ) start += len; return len == -1 ? -1 : start; }
private final int readLine( final FastBufferedInputStream fbis ) throws IOException { int start = 0, len; while( ( len = fbis.readLine( lineBuffer, start, lineBuffer.length - start, FastBufferedInputStream.ALL_TERMINATORS ) ) == lineBuffer.length - start ) { start += len; lineBuffer = ByteArrays.grow( lineBuffer, lineBuffer.length + 1 ); } if ( len != -1 ) start += len; return len == -1 ? -1 : start; }
private final int readLine( final FastBufferedInputStream fbis ) throws IOException { int start = 0, len; while( ( len = fbis.readLine( lineBuffer, start, lineBuffer.length - start, FastBufferedInputStream.ALL_TERMINATORS ) ) == lineBuffer.length - start ) { start += len; lineBuffer = ByteArrays.grow( lineBuffer, lineBuffer.length + 1 ); } if ( len != -1 ) start += len; return len == -1 ? -1 : start; }
public MutableString get(final long index, final FastBufferedInputStream fastBufferedInputStream, final ByteBuffer byteBuffer, final CharBuffer charBuffer, final CharsetDecoder decoder) { try { fastBufferedInputStream.position(borders.getLong(index)); byteBuffer.clear(); byteBuffer.limit(fastBufferedInputStream.readLine(byteBuffer.array(), terminators)); charBuffer.clear(); decoder.decode(byteBuffer, charBuffer, true); return new MutableString(charBuffer.array(), 0, charBuffer.position()); } catch (final IOException e) { throw new RuntimeException(e); } }
public MutableString get(final int index, final FastBufferedInputStream fastBufferedInputStream, final ByteBuffer byteBuffer, final CharBuffer charBuffer, final CharsetDecoder decoder) { try { fastBufferedInputStream.position(borders.getLong(index)); byteBuffer.clear(); byteBuffer.limit(fastBufferedInputStream.readLine(byteBuffer.array(), terminators)); charBuffer.clear(); decoder.decode(byteBuffer, charBuffer, true); return new MutableString(charBuffer.array(), 0, charBuffer.position()); } catch (final IOException e) { throw new RuntimeException(e); } }
@Override public long nextLong() { if (! hasNext()) throw new NoSuchElementException(); pos++; try { final long result = inputStream.position(); inputStream.readLine(buffer, terminators); return result; } catch (final IOException e) { throw new RuntimeException(e); } } });
@Override public long nextLong() { if (! hasNext()) throw new NoSuchElementException(); pos++; try { final long result = inputStream.position(); inputStream.readLine(buffer, terminators); return result; } catch (final IOException e) { throw new RuntimeException(e); } } });
@Override public boolean hasNext() { if (ready) return true; if (fbis == null) return false; ready = false; try { read = 0; int len; while((len = fbis.readLine(buffer, read, buffer.length - read, terminators)) == buffer.length - read) { ready = true; read += len; buffer = ByteArrays.grow(buffer, buffer.length + 1); } if (len != -1) { ready = true; read += len; } if (len == -1) close(); } catch (final IOException e) { throw new RuntimeException(e); } return ready; }
public Document getDocument( InputStream rawContent, Reference2ObjectMap<Enum<?>,Object> metadata ) throws IOException { final FastBufferedInputStream fbis = new FastBufferedInputStream( rawContent ); int startedHeader = 0; // 0 == false, 1 == true, 2 === header started and uri collected boolean foundDocNo = false; int l = fbis.readLine( buffer ); if ( l < 0 ) throw new EOFException(); if ( ! TRECDocumentCollection.equals( buffer, l, DOC_OPEN ) ) throw new IllegalStateException ( "Document does not start with <DOC>: " + new String( buffer, 0, l ) ); while ( ( l = fbis.readLine( buffer ) ) != -1 ) { if ( !foundDocNo && startsWith( buffer, l, DOCNO_OPEN ) ) { foundDocNo = true; metadata.put( MetadataKeys.TITLE, new String( buffer, DOCNO_OPEN.length, l - ( DOCNO_OPEN.length + DOCNO_CLOSE.length ) ) ); } switch ( startedHeader ) { case 0: if ( TRECDocumentCollection.equals( buffer, l, DOCHDR_OPEN ) ) startedHeader = 1; break; case 1: startedHeader = 2; metadata.put( MetadataKeys.URI, new String( buffer, 0, l ) ); break; case 2: } if ( TRECDocumentCollection.equals( buffer, l, DOCHDR_CLOSE ) ) break; } return new TRECHeaderDocument( metadata ); }
public Document getDocument( InputStream rawContent, Reference2ObjectMap<Enum<?>,Object> metadata ) throws IOException { final FastBufferedInputStream fbis = new FastBufferedInputStream( rawContent ); int startedHeader = 0; // 0 == false, 1 == true, 2 === header started and uri collected boolean foundDocNo = false; int l = fbis.readLine( buffer ); if ( l < 0 ) throw new EOFException(); if ( ! TRECDocumentCollection.equals( buffer, l, DOC_OPEN ) ) throw new IllegalStateException ( "Document does not start with <DOC>: " + new String( buffer, 0, l ) ); while ( ( l = fbis.readLine( buffer ) ) != -1 ) { if ( !foundDocNo && startsWith( buffer, l, DOCNO_OPEN ) ) { foundDocNo = true; metadata.put( MetadataKeys.TITLE, new String( buffer, DOCNO_OPEN.length, l - ( DOCNO_OPEN.length + DOCNO_CLOSE.length ) ) ); } switch ( startedHeader ) { case 0: if ( TRECDocumentCollection.equals( buffer, l, DOCHDR_OPEN ) ) startedHeader = 1; break; case 1: startedHeader = 2; metadata.put( MetadataKeys.URI, new String( buffer, 0, l ) ); break; case 2: } if ( TRECDocumentCollection.equals( buffer, l, DOCHDR_CLOSE ) ) break; } return new TRECHeaderDocument( metadata ); }
boolean foundDocNo = false; int l = fbis.readLine( buffer ); if ( l < 0 ) throw new EOFException(); if ( ! TRECDocumentCollection.equals( buffer, l, DOC_OPEN ) ) throw new IllegalStateException ( "Document does not start with <DOC>: " + new String( buffer, 0, l ) ); while ( ( l = fbis.readLine( buffer ) ) != -1 ) { if ( !foundDocNo && startsWith( buffer, l, DOCNO_OPEN ) ) { foundDocNo = true;
boolean foundDocNo = false; int l = fbis.readLine( buffer ); if ( l < 0 ) throw new EOFException(); if ( ! TRECDocumentCollection.equals( buffer, l, DOC_OPEN ) ) throw new IllegalStateException ( "Document does not start with <DOC>: " + new String( buffer, 0, l ) ); while ( ( l = fbis.readLine( buffer ) ) != -1 ) { if ( !foundDocNo && startsWith( buffer, l, DOCNO_OPEN ) ) { foundDocNo = true;