Package java.nio.channels

Examples of java.nio.channels.FileChannel


      throws IOException
   {
      if( addDefaultHeader )
      {
         FileInputStream fis = new FileInputStream(javaFile);
         FileChannel fc = fis.getChannel();
         int size = (int) fc.size();
         ByteBuffer contents = ByteBuffer.allocate(size);
         fc.read(contents);
         fis.close();
        
         ByteBuffer hdr = ByteBuffer.wrap(DEFAULT_HEADER.getBytes());
         FileOutputStream fos = new FileOutputStream(javaFile);
         fos.write(hdr.array());
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 serverChannel = reqHdl.dataSinkRef.get();
   
   
    File file = QAUtil.createTempfile();
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
   
    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    QAUtil.sleep(200);
   
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
   
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
View Full Code Here

   
    BodyDataSink serverChannel = reqHdl.dataSinkRef.get();
   
    File file = QAUtil.createTempfile();
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
   
    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    server.close();
   
    QAUtil.sleep(1000);

    try {
        fc.transferFrom(clientChannel, 0, 17);
        Assert.fail("IOException expected");
    } catch (IOException expected) { }

    file.delete();
    server.close();
View Full Code Here

   
        BodyDataSink serverChannel = reqHdl.dataSinkRef.get();
   
    File file = QAUtil.createTempfile();
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
   
    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    serverChannel.close();
    QAUtil.sleep(200);
   
    long transfered = fc.transferFrom(clientChannel, 0, 9000000);
    fc.close();
    raf.close();
   
    Assert.assertEquals(txt.length(), transfered);
    Assert.assertTrue(QAUtil.isEquals(file, txt));
   
View Full Code Here

 
   
    File file = QAUtil.createTempfile();
    System.out.println(file.getAbsolutePath());
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
   
    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    QAUtil.sleep(200);
   
    clientChannel.close();
   
    try {
      fc.transferFrom(clientChannel, 0, 9000000);
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
    file.delete();
    server.close();
View Full Code Here

        BodyDataSink serverChannel = reqHdl.dataSinkRef.get();
 
   
    File file = QAUtil.createTempfile();
    RandomAccessFile raf = new RandomAccessFile(file, "rw");
    FileChannel fc = raf.getChannel();
   
    String txt = "Hello my client\r\n";
    serverChannel.write(txt);
    serverChannel.flush();
    QAUtil.sleep(200);
   
    clientChannel.close();
   
    try {
      fc.transferFrom(clientChannel, 0, 9000000);
      Assert.fail("ClosedChannelException expected");
    } catch (ClosedChannelException expected) { }
   
    file.delete();
    server.close();
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.