Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


    ByteBuffer buf = this.getBuffer();
    buf.rewind();

    // Fix for https://github.com/plutext/docx4j/issues/80
    // from http://stackoverflow.com/questions/579600/how-to-put-the-content-of-a-bytebuffer-into-an-outputstream
        WritableByteChannel channel = Channels.newChannel(out);
        channel.write(buf);       
    buf.rewind();
       
  }
View Full Code Here


         if (position + length >= spoolChannel.size())
            length = spoolChannel.size() - position;

         MappedByteBuffer bb = spoolChannel.map(FileChannel.MapMode.READ_ONLY, position, length);

         WritableByteChannel ch = Channels.newChannel(stream); // TODO don't use Channels.newChannel
         ch.write(bb);
         ch.close();

         return length;
      }
   }
View Full Code Here

      }
      else
      {
         // it's user stream (not a file)
         ReadableByteChannel inch = inFile ? ((FileInputStream)in).getChannel() : Channels.newChannel(in);
         WritableByteChannel outch = outFile ? ((FileOutputStream)out).getChannel() : Channels.newChannel(out);

         // TODO buffers show same perfomance as bytes copy via Input/Output streams
         // NIO buffers article http://www.odi.ch/weblog/posting.php?posting=371
         long size = 0;
         int r = 0;
         ByteBuffer buff = ByteBuffer.allocate(IOBUFFER_SIZE);
         buff.clear();
         while ((r = inch.read(buff)) >= 0)
         {
            buff.flip();

            // copy all
            do
            {
               outch.write(buff);
            }
            while (buff.hasRemaining());

            buff.clear();
            size += r;
View Full Code Here

        MessageEvent e = (MessageEvent) evt;
        Object originalMessage = e.getMessage();
        if (originalMessage instanceof FileRegion) {

            FileRegion fr = (FileRegion) originalMessage;
            WritableByteChannel bchannel = new ChannelWritableByteChannel(ctx, e);

            int length = 0;
            long i = 0;
            while ((i = fr.transferTo(bchannel, length)) > 0) {
                length += i;
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 WritableByteChannel newChannel(final OutputStream out) {
  return new WritableByteChannel() {
      private boolean open = true;

      public int write(ByteBuffer src) throws IOException {
    assert src.hasArray();
View Full Code Here

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

                //configure output channel
                sc = attachment.getChannel();
                sc.setSendFile(true);
                //ssl channel is slightly different
                WritableByteChannel wc =(WritableByteChannel) ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());

                //we still have data in the buffer
                if (sc.getOutboundRemaining()>0) {
                    if (sc.flushOutbound()) {
                        attachment.access();
View Full Code Here

   }

   @Override
   public void copyTo(OutputStream stream) throws IOException {
      // Wrap the OutputSteam as a channel
      WritableByteChannel out = Channels.newChannel(stream);
      // Now do the transfer
      channel.transferTo(0, channel.size(), out);
   }
View Full Code Here

                    }
                    sd.fchannel = new FileInputStream(f).getChannel();
                }
                sc = attachment.getChannel();
                sc.setSendFile(true);
                WritableByteChannel wc = ((sc instanceof SecureNioChannel)?sc:sc.getIOChannel());
               
                if (sc.getOutboundRemaining()>0) {
                    if (sc.flushOutbound()) {
                        attachment.access();
                    }
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.