Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


      throw new RuntimeException(
          "File for that location does not exist (or timed out)");
    }
    try {
      if(obj instanceof WritableByteChannel){
        WritableByteChannel channel=(WritableByteChannel)obj;
        channel.write(chunk);
        uploaders.put(location, channel);
      }
    } catch (IOException e) {
      LOG.error(" WritableByteChannel write filed when uploadChunk "
          + location);
View Full Code Here


      throw new RuntimeException(
          "File for that location does not exist (or timed out)");
    }
    try {
      if(obj instanceof WritableByteChannel){
        WritableByteChannel channel=(WritableByteChannel)obj;
        channel.close();
        LOG.info("Finished uploading file from client: " + location);
        uploaders.remove(location);
      }
    } catch (IOException e) {
      LOG.error(" WritableByteChannel close failed when finishFileUpload "
View Full Code Here

  public static void downloadFromMaster(Map conf, String file,
      String localFile) throws IOException, TException {
    NimbusClient client = NimbusClient.getConfiguredClient(conf);
    String id = client.getClient().beginFileDownload(file);
    WritableByteChannel out = Channels.newChannel(new FileOutputStream(
        localFile));
    while (true) {
      ByteBuffer chunk = client.getClient().downloadChunk(id);
      int written = out.write(chunk);
      if (written == 0)
        break;
    }
    out.close();
  }
View Full Code Here

   */
  public static void copy(Bucket src, Bucket dst) throws IOException {
    OutputStream out = dst.getOutputStreamUnbuffered();
    InputStream in = src.getInputStreamUnbuffered();
    ReadableByteChannel readChannel = Channels.newChannel(in);
    WritableByteChannel writeChannel = Channels.newChannel(out);
    try {

    // No benefit to allocateDirect() as we're wrapping streams anyway, and worse, it'd be a memory leak.
    ByteBuffer buffer = ByteBuffer.allocate(BUFFER_SIZE);
    while (readChannel.read(buffer) != -1) {
      buffer.flip();
      while(buffer.hasRemaining())
        writeChannel.write(buffer);
      buffer.clear();
    }

    } finally {
    writeChannel.close();
    readChannel.close();
    }
  }
View Full Code Here

    }

    public static void downloadFromMaster(Map conf, String file, String localFile) throws IOException, TException {
        NimbusClient client = NimbusClient.getConfiguredClient(conf);
        String id = client.getClient().beginFileDownload(file);
        WritableByteChannel out = Channels.newChannel(new FileOutputStream(localFile));
        while(true) {
            ByteBuffer chunk = client.getClient().downloadChunk(id);
            int written = out.write(chunk);
            if(written==0) break;
        }
        out.close();
    }
View Full Code Here

        }
         ** End mod */

        FileInputStream fis = null;
        FileChannel in = null;
        WritableByteChannel out = null;

        // serve up image from proper location
        // Use local file system if the image is in default location.
        logger.finer("AcessArtifact -- imagePath = " + imagePath);
        InputStream is = null;
View Full Code Here

                    }
                    sd.fchannel = new FileInputStream(f).getChannel();
                }
                sc = attachment.getChannel();
                sc.setSendFile(true);
                WritableByteChannel wc =(WritableByteChannel) ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());
               
                if (sc.getOutboundRemaining()>0) {
                    if (sc.flushOutbound()) {
                        attachment.access();
                    }
View Full Code Here

        return Channels.newChannel(baos);
    }
   
    public void testBasicCoding() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();

        LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
View Full Code Here

        assertEquals("stuff;more stuff", s);
    }
   
    public void testCodingBeyondContentLimit() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();

        LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
View Full Code Here

        assertEquals("stuff;more stuff", s);
    }
   
    public void testCodingEmptyBuffer() throws Exception {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        WritableByteChannel channel = newChannel(baos);
        HttpParams params = new BasicHttpParams();
        SessionOutputBuffer outbuf = new SessionOutputBufferImpl(1024, 128, params);
        HttpTransportMetricsImpl metrics = new HttpTransportMetricsImpl();

        LengthDelimitedEncoder encoder = new LengthDelimitedEncoder(
View Full Code Here

TOP

Related Classes of java.nio.channels.WritableByteChannel

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.