当前位置: 首页>>代码示例>>Java>>正文


Java FastBufferedInputStream.read方法代码示例

本文整理汇总了Java中it.unimi.dsi.fastutil.io.FastBufferedInputStream.read方法的典型用法代码示例。如果您正苦于以下问题:Java FastBufferedInputStream.read方法的具体用法?Java FastBufferedInputStream.read怎么用?Java FastBufferedInputStream.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在it.unimi.dsi.fastutil.io.FastBufferedInputStream的用法示例。


在下文中一共展示了FastBufferedInputStream.read方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: skip

import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
@Override
public void skip(final FastBufferedInputStream is) throws IOException {
	int length = 0, b;

	while((b = is.read()) >= 0x80) {
		length |= b & 0x7F;
		length <<= 7;
	}
	if (b == -1) throw new EOFException();
	length |= b;

	final long actual = is.skip(length);
	if (actual != length) throw new IOException("Asked for " + length + " but got " + actual);
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:15,代码来源:ByteSerializerDeserializer.java

示例2: skip

import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
@Override
public void skip(final FastBufferedInputStream is) throws IOException {
	// Borrowed from it.unimi.dsi.lang.MutableString.
	int length = 0, b;

	for(;;) {
		if ((b = is.read()) < 0) throw new EOFException();
		if ((b & 0x80) == 0) break;
		length |= b & 0x7F;
		length <<= 7;
	}
	length |= b;

	for(int i = 0; i < length; i++) {
		b = is.read() & 0xFF;
		switch (b >> 4) {
		case 0:
		case 1:
		case 2:
		case 3:
		case 4:
		case 5:
		case 6:
		case 7:
			break;
		case 12:
		case 13:
			is.skip(1);
			break;
		case 14:
			is.skip(2);
			break;
		default:
			throw new UTFDataFormatException();
		}
	}
}
 
开发者ID:LAW-Unimi,项目名称:BUbiNG,代码行数:38,代码来源:CharSequenceByteSerializerDeserializer.java

示例3: phase1

import it.unimi.dsi.fastutil.io.FastBufferedInputStream; //导入方法依赖的package包/类
public List<String> phase1(int id, String name, int numJCLThreads) {
    Int2LongMap values = new Int2LongOpenHashMap(1000000);
    long totalF = 0;
    System.err.println("file: " + name);
    try {
        File f = new File("../" + name + "/" + name + ".bin");
        InputStream in = new BufferedInputStream(new FileInputStream(f));
        FastBufferedInputStream fb = new FastBufferedInputStream(in);
        byte[] i = new byte[4];
        while (fb.read(i) == 4) {
            int k = java.nio.ByteBuffer.wrap(i).getInt();
            if (!values.containsKey(k))
                values.put(k, 1);
            else {
                long aux = values.get(k);
                aux++;
                values.put(k, aux);
            }
            totalF++;
        }
        fb.close();
        in.close();
        
        // primeira modificacao
        //for (long v : values.values())
        //    totalF += v;
        
        IntSet sorted = new IntAVLTreeSet(values.keySet());
        long acumula = 0;
        int b = 0;
        List<String> result = new LinkedList<>();
        long blinha = 0; 
        int last = 0;
        for (int ac : sorted) {
            blinha = values.get(ac);
            acumula += blinha;
            if (acumula > (totalF / (numJCLThreads))) {
                b = ac;
                result.add(b + ":" + acumula);
                acumula = 0;
            }
            last = ac;
        }
        
        // segunda modificacao
        if(acumula != 0) result.add(last + ":" + acumula);
        
        JCL_facade jcl = JCL_FacadeImpl.getInstanceLambari();
        jcl.instantiateGlobalVar(id, values);
        sorted.clear();
        sorted = null;
        return result;

    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:59,代码来源:Sorting.java

示例4: 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;
		}
	}

}
 
开发者ID:phishman3579,项目名称:fastutil,代码行数:74,代码来源:FastBufferedInputStreamTest.java


注:本文中的it.unimi.dsi.fastutil.io.FastBufferedInputStream.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。