Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


     * channel is already closed
     */
    public int internalWrite(ByteBuffer buffer) throws IOException, BadDescriptorException {
        checkOpen();
       
        WritableByteChannel writeChannel = (WritableByteChannel)channel;
       
        if (isSeekable() && originalModes.isAppendable()) {
            FileChannel fileChannel = (FileChannel)channel;
            fileChannel.position(fileChannel.size());
        }
       
        return writeChannel.write(buffer);
    }
View Full Code Here


                //configure output channel
                sc = attachment.getChannel();
                sc.setSendFile(true);
                //ssl channel is slightly different
                WritableByteChannel wc = ((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

    final FileOutputStream os = new FileOutputStream(filename);
    try {
      final DataOutput out = new OutputStreamDataOutput(os);
      CodecUtil.writeHeader(out, BinaryDictionary.DICT_HEADER, BinaryDictionary.VERSION);
      out.writeVInt(buffer.position());
      final WritableByteChannel channel = Channels.newChannel(os);
      // Write Buffer
      buffer.flip()// set position to 0, set limit to current position
      channel.write(buffer);
      assert buffer.remaining() == 0L;
    } finally {
      os.close();
    }
  }
View Full Code Here

    DbusEventBufferBatchReadable reader =
        _eventBufferMult.getDbusEventBufferBatchReadable(cpMult, Arrays.asList(pkeys), statsColl);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    WritableByteChannel writeChannel = Channels.newChannel(baos);
    reader.streamEvents(false, 1000000, writeChannel, Encoding.BINARY, new AllowAllDbusFilter());
    writeChannel.close();
    baos.close();

    //make sure we got the physical partition names right
    List<String> ppartNames = statsColl.getStatsCollectorKeys();
    assertEquals(ppartNames.size(), 3);
View Full Code Here

    DbusEventBufferBatchReadable reader =
        _eventBufferMult.getDbusEventBufferBatchReadable(cpMult, Arrays.asList(pkeys), statsColl);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    WritableByteChannel writeChannel = Channels.newChannel(baos);
    // Set streamFromLatestScn == true
    reader.streamEvents(true, 1000000, writeChannel, Encoding.BINARY, new AllowAllDbusFilter());
    writeChannel.close();
    baos.close();

    //make sure we got the physical partition names right
    List<String> ppartNames = statsColl.getStatsCollectorKeys();
    assertEquals(ppartNames.size(), 1);
View Full Code Here

    DbusEventBufferBatchReadable reader =
        _eventBufferMult.getDbusEventBufferBatchReadable(cpMult, Arrays.asList(pkeys), statsColl);

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    WritableByteChannel writeChannel = Channels.newChannel(baos);
    // Set streamFromLatestScn == true
    reader.streamEvents(true, 1000000, writeChannel, Encoding.BINARY, new AllowAllDbusFilter());
    writeChannel.close();
    baos.close();

    //make sure we got the physical partition names right
    List<String> ppartNames = statsColl.getStatsCollectorKeys();
    assertEquals(ppartNames.size(), 3);
View Full Code Here

    while(numEventsRead > 0) {
      if(iterCount++ > maxIterNum) {
        fail("Checkpoint doesn't work - it is a never-ending loop");
      }
      ByteArrayOutputStream jsonOut = new ByteArrayOutputStream();
      WritableByteChannel jsonOutChannel = Channels.newChannel(jsonOut);

      numEventsRead = read.streamEvents(false, batchFetchSize, jsonOutChannel,
                                        Encoding.JSON_PLAIN_VALUE,  new SourceDbusFilter(srcIds)).getNumEventsStreamed();

      totalRead += numEventsRead;
View Full Code Here

  public void streamEvents() throws ScnNotFoundException,
      OffsetNotFoundException
  {
    _srcByteStr = new ByteArrayOutputStream();
    final WritableByteChannel srcChannel = Channels.newChannel(_srcByteStr);
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    _srcBufStats.reset();

    StreamEventsArgs args = new StreamEventsArgs(_srcBufferSize).setStatsCollector(_srcBufStats);
View Full Code Here

     * Dispose of this <code>OutputStreamImageDataReceiver</code> and its
     * resources.
     */
    public synchronized void dispose() {
        if ( m_channel != null ) {
            final WritableByteChannel temp = m_channel;
            m_channel = null;
            try {
                temp.close();
            }
            catch ( IOException e ) {
                e.printStackTrace();
            }
        }
View Full Code Here

        return resourceName;
    }

    public static void copyStreamContent(InputStream is, OutputStream os) throws IOException {
        ReadableByteChannel inChannel = Channels.newChannel(is);
        WritableByteChannel outChannel = Channels.newChannel(os);

        // TODO make this configurable
        ByteBuffer buffer = ByteBuffer.allocate(8192);
        int read;

        while ((read = inChannel.read(buffer)) > 0) {
            buffer.rewind();
            buffer.limit(read);

            while (read > 0) {
                read -= outChannel.write(buffer);
            }

            buffer.clear();
        }
    }
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.