本文整理汇总了Java中it.unimi.dsi.fastutil.io.FastBufferedInputStream.position方法的典型用法代码示例。如果您正苦于以下问题:Java FastBufferedInputStream.position方法的具体用法?Java FastBufferedInputStream.position怎么用?Java FastBufferedInputStream.position使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类it.unimi.dsi.fastutil.io.FastBufferedInputStream
的用法示例。
在下文中一共展示了FastBufferedInputStream.position方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
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);
}
}
示例2: get
import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
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);
}
}
示例3: testRandom
import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
@SuppressWarnings("resource")
public void testRandom( int bufferSize ) throws IOException {
File temp = File.createTempFile( this.getClass().getSimpleName(), "tmp" );
temp.deleteOnExit();
// Create temp random file
FileOutputStream out = new FileOutputStream( temp );
Random random = new Random();
int length = 100000 + random.nextInt( 10000 );
for( int i = 0; i < length; i++ ) out.write( random.nextInt() );
out.close();
FastBufferedInputStream bis = new FastBufferedInputStream( new FileInputStream( temp ), bufferSize );
FileInputStream test = new FileInputStream( temp );
FileChannel fc = test.getChannel();
int a1, a2, off, len, pos;
byte b1[] = new byte[ 32768 ];
byte b2[] = new byte[ 32768 ];
while( true ) {
switch( random.nextInt( 6 ) ) {
case 0:
if ( DEBUG ) System.err.println("read()");
a1 = bis.read();
a2 = test.read();
assertEquals( a1, a2 );
if ( a1 == -1 ) return;
break;
case 1:
off = random.nextInt( b1.length );
len = random.nextInt( b1.length - off + 1 );
a1 = bis.read( b1, off, len );
a2 = test.read( b2, off, len );
if ( DEBUG ) System.err.println("read(b, " + off + ", " + len + ")");
assertEquals( a1, a2 );
for( int i = off; i < off + len; i++ ) assertEquals( "Position " + i, b1[ i ], b2[ i ] );
break;
case 2:
if ( DEBUG ) System.err.println("available()");
assertEquals( bis.available(), test.available() );
break;
case 3:
if ( DEBUG ) System.err.println("position()" );
pos = (int)bis.position();
assertEquals( (int)fc.position(), pos );
break;
case 4:
pos = random.nextInt( length );
bis.position( pos );
if ( DEBUG ) System.err.println("position(" + pos + ")" );
(test = new FileInputStream( temp )).skip( pos );
fc = test.getChannel();
break;
case 5:
pos = random.nextInt( (int)(length - bis.position() + 1) );
a1 = (int)bis.skip( pos );
a2 = (int)test.skip( pos );
if ( DEBUG ) System.err.println("skip(" + pos + ")" );
assertEquals( a1, a2 );
break;
}
}
}
示例4: FileLinesList
import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
/** Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.
*
* @param filename a filename.
* @param encoding an encoding.
* @param bufferSize the buffer size for {@link FastBufferedInputStream}.
* @param terminators a set of line terminators.
*/
public FileLinesList(final CharSequence filename, final String encoding, final int bufferSize, final EnumSet<FastBufferedInputStream.LineTerminator> terminators) throws IOException {
this.bufferSize = bufferSize;
this.terminators = terminators;
this.filename = filename.toString();
inputStream = new FastBufferedInputStream(new FileInputStream(this.filename), bufferSize);
decoder = (charset = Charset.forName(encoding)).newDecoder();
byte[] array = new byte[16];
int count = 0, start, len;
for(;;) {
start = 0;
while((len = inputStream.readLine(array, start, array.length - start, terminators)) == array.length - start) {
start += len;
array = ByteArrays.grow(array, array.length + 1);
};
if (len != -1) count++;
else break;
}
size = count;
byteBuffer = ByteBuffer.wrap(array);
charBuffer = CharBuffer.wrap(new char[array.length]);
inputStream.position(0);
borders = new EliasFanoMonotoneLongBigList(count, inputStream.length(), new LongIterator() {
long pos = 0;
byte[] buffer = byteBuffer.array();
@Override
public boolean hasNext() {
return pos < size;
}
@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);
}
}
});
}
示例5: FileLinesBigList
import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
/** Creates a file-lines collection for the specified filename with the specified encoding, buffer size and terminator set.
*
* @param filename a filename.
* @param encoding an encoding.
* @param bufferSize the buffer size for {@link FastBufferedInputStream}.
* @param terminators a set of line terminators.
*/
public FileLinesBigList(final CharSequence filename, final String encoding, final int bufferSize, final EnumSet<FastBufferedInputStream.LineTerminator> terminators) throws IOException {
this.bufferSize = bufferSize;
this.terminators = terminators;
this.filename = filename.toString();
inputStream = new FastBufferedInputStream(new FileInputStream(this.filename), bufferSize);
decoder = (charset = Charset.forName(encoding)).newDecoder();
byte[] array = new byte[16];
long count = 0;
int start, len;
for(;;) {
start = 0;
while((len = inputStream.readLine(array, start, array.length - start, terminators)) == array.length - start) {
start += len;
array = ByteArrays.grow(array, array.length + 1);
};
if (len != -1) count++;
else break;
}
size = count;
byteBuffer = ByteBuffer.wrap(array);
charBuffer = CharBuffer.wrap(new char[array.length]);
inputStream.position(0);
borders = new EliasFanoMonotoneLongBigList(count, inputStream.length(), new LongIterator() {
long pos = 0;
byte[] buffer = byteBuffer.array();
@Override
public boolean hasNext() {
return pos < size;
}
@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);
}
}
});
}