Package java.nio.channels

Examples of java.nio.channels.FileChannel


    BodyDataSink clientChannel = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
   
    File file = QAUtil.createTestfile_40k();
    file.deleteOnExit();
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    FileChannel fc = raf.getChannel();
   
    fc.transferTo(0, fc.size(), clientChannel);

    clientChannel.close();
    fc.close();
    raf.close();
   
   
    Assert.assertEquals(200, respHdl.getResponse().getStatus());
View Full Code Here


    }
   

  static ByteBuffer[] readFile(File file) throws IOException {
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate((int) fc.size());
        fc.read(buffer);
        fc.close();
        raf.close();
        buffer.flip();
       
        return new ByteBuffer[] { buffer };
    }
View Full Code Here

        byte[] header = sb.toString().getBytes("US-ASCII");
       
       
        // create content
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate((int) fc.size());
        fc.read(buffer);
        fc.close();
        raf.close();
        buffer.flip();
       
        // add part
        addPart(DataConverter.toByteBuffer(header), buffer);
View Full Code Here

 
    public static boolean isEquals(File file, File file2) throws IOException {
       
      RandomAccessFile raf = new RandomAccessFile(file2, "r");
        FileChannel fc = raf.getChannel();
        ByteBuffer buf = ByteBuffer.allocate((int) fc.size());
        fc.read(buf);
        buf.flip();
       
        boolean isEquals = isEquals(file, new ByteBuffer[] { buf });
       
        fc.close();
        raf.close();
       
        return isEquals;
    }
View Full Code Here

    for (ByteBuffer byteBuffer : buffers) {
      length += byteBuffer.remaining();
    }

    RandomAccessFile raf = new RandomAccessFile(file, "r");
    FileChannel fc = raf.getChannel();
    ByteBuffer buf = ByteBuffer.allocate(length);
    fc.read(buf);
    buf.flip();
   
    boolean isEquals = isEquals(buf, buffers);
   
    fc.close();
    raf.close();
   
    return isEquals;
  }
View Full Code Here

   
    File file = QAUtil.createTempfile();
    System.out.println("write to file " + file.getAbsolutePath());
     
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
    response.getBody().transferTo(fc);
    fc.close();
    raf.close();

    LineNumberReader lnr = new LineNumberReader(new FileReader(file));
    String line = lnr.readLine();
   
View Full Code Here

        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
       
       
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();
        dataSink.transferFrom(fc);
        fc.close();
        raf.close();
        dataSink.close();
       
        IHttpResponse response = respHdl.getResponse();
       
View Full Code Here

        FutureResponseHandler respHdl = new FutureResponseHandler();
        BodyDataSink dataSink = con.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/"), respHdl);
       
       
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();
        dataSink.transferFrom(fc);
        fc.close();
        raf.close();
        dataSink.close();
       
        IHttpResponse response = respHdl.getResponse();
       
View Full Code Here

        byte[] header = sb.toString().getBytes("US-ASCII");
       
       
        // create content
        RandomAccessFile raf = new RandomAccessFile(file, "r");
        FileChannel fc = raf.getChannel();

        ByteBuffer buffer = ByteBuffer.allocate((int) fc.size());
        fc.read(buffer);
        fc.close();
        raf.close();
        buffer.flip();
       
        // add part
        addPart(DataConverter.toByteBuffer(header), buffer);
View Full Code Here

   
    BodyDataSink clientChannel = httpClient.send(new HttpRequestHeader("POST", "http://localhost:" + server.getLocalPort() + "/test/resource"), respHdl);
   
    File file = QAUtil.createTestfile_40k();
    RandomAccessFile raf = new RandomAccessFile(file, "r");
    FileChannel fc = raf.getChannel();
   
    fc.transferTo(0, fc.size(), clientChannel);
   
    clientChannel.close();
    fc.close();
    raf.close();
   
    Assert.assertEquals(200, respHdl.getResponse().getStatus());
   
    Assert.assertTrue(QAUtil.isEquals(file, new ByteBuffer[] { ByteBuffer.wrap(reqHdl.getDataSource().readBytes()) }));
View Full Code Here

TOP

Related Classes of java.nio.channels.FileChannel

Copyright © 2018 www.massapicom. 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.