Package java.nio.channels

Examples of java.nio.channels.FileChannel.position()


        Random random = new Random(1);
        random.nextBytes(buffer);
        channel.write(ByteBuffer.wrap(buffer));
        assertEquals(10000, channel.size());
        channel.position(20000);
        assertEquals(20000, channel.position());
        assertEquals(-1, channel.read(ByteBuffer.wrap(buffer, 0, 1)));
        String path = fsBase + "/test";
        assertEquals("test", FileUtils.getName(path));
        can = FilePath.get(fsBase).toRealPath().toString();
        String can2 = FileUtils.toRealPath(FileUtils.getParent(path));
View Full Code Here


                switch(random.nextInt(7)) {
                case 0: {
                    pos = (int) Math.min(pos, ra.length());
                    trace("seek " + pos);
                    buff.append("seek " + pos + "\n");
                    f.position(pos);
                    ra.seek(pos);
                    break;
                }
                case 1: {
                    byte[] buffer = new byte[random.nextInt(1000)];
View Full Code Here

                    if (pos < ra.length()) {
                        // truncate is supposed to have no effect if the
                        // position is larger than the current size
                        ra.setLength(pos);
                    }
                    assertEquals("truncate " + pos, ra.getFilePointer(), f.position());
                    buff.append("truncate " + pos + "\n");
                    break;
                }
                case 3: {
                    int len = random.nextInt(1000);
View Full Code Here

                    break;
                }
                case 4: {
                    trace("getFilePointer " + ra.getFilePointer());
                    buff.append("getFilePointer " + ra.getFilePointer() + "\n");
                    assertEquals(ra.getFilePointer(), f.position());
                    break;
                }
                case 5: {
                    trace("length " + ra.length());
                    buff.append("length " + ra.length() + "\n");
View Full Code Here

        }
        FileChannel fc = null;
        try {
            if (getEndpoint().isAppend()) {
                fc = new RandomAccessFile(file, "rw").getChannel();
                fc.position(fc.size());
            } else {
                fc = new FileOutputStream(file).getChannel();
            }
            int size = getEndpoint().getBufferSize();
            byte[] buffer = new byte[size];
View Full Code Here

            blockIn instanceof FileInputStream) {
         
          FileChannel fileChannel = ((FileInputStream)blockIn).getChannel();
         
          // blockInPosition also indicates sendChunks() uses transferTo.
          blockInPosition = fileChannel.position();
          streamForSendChunks = baseStream;
         
          // assure a mininum buffer size.
          maxChunksPerPacket = (Math.max(BUFFER_SIZE,
                                         MIN_BUFFER_WITH_TRANSFERTO)
View Full Code Here

            ByteBuffer hashset;
            FileChannel fc = fis.getChannel();
            MD4 msgDigest = new MD4();
            ByteBuffer bb = ByteBuffer.allocateDirect(16384).order(ByteOrder.LITTLE_ENDIAN);
            ByteBuffer di = ByteBuffer.allocate(16).order(ByteOrder.LITTLE_ENDIAN);
            log.finest( "pos:" + fc.position() );

            c = (int) ((fc.size() + PARTSIZE - 1) / PARTSIZE);
            log.finer("hash "+c+" EdonkeyParts");
            // we will need space for c Parts
            hashset = ByteBuffer.allocate(16 * (c>0?c:1)).order(ByteOrder.LITTLE_ENDIAN);
 
View Full Code Here

            c = (int) ((fc.size() + PARTSIZE - 1) / PARTSIZE);
            log.finer("hash "+c+" EdonkeyParts");
            // we will need space for c Parts
            hashset = ByteBuffer.allocate(16 * (c>0?c:1)).order(ByteOrder.LITTLE_ENDIAN);
            for (i = 1; i < c; i++) {
                log.finest( "filechannel pos:" + fc.position()+" part: "+i+" of "+c );
                while (fc.position() <= (i * PARTSIZE - bb.capacity())) {
                    fc.read(bb);
                    bb.flip();
                    msgDigest.update(bb);
                    bb.rewind();
View Full Code Here

            log.finer("hash "+c+" EdonkeyParts");
            // we will need space for c Parts
            hashset = ByteBuffer.allocate(16 * (c>0?c:1)).order(ByteOrder.LITTLE_ENDIAN);
            for (i = 1; i < c; i++) {
                log.finest( "filechannel pos:" + fc.position()+" part: "+i+" of "+c );
                while (fc.position() <= (i * PARTSIZE - bb.capacity())) {
                    fc.read(bb);
                    bb.flip();
                    msgDigest.update(bb);
                    bb.rewind();
                    try {
View Full Code Here

                      Thread.currentThread().sleep(5);
                    }
                    catch (InterruptedException ex) {
                    }
                }
                log.finest( "filechannel pos:" + fc.position()+" part: "+i+" of "+c );
                if (fc.position() < (i * PARTSIZE)) {
                    bb.limit((int) ((i * PARTSIZE) - fc.position()));
                    fc.read(bb);
                    bb.flip();
                    msgDigest.update(bb);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.