Examples of ReadableByteChannel


Examples of java.nio.channels.ReadableByteChannel

          BodyDataSink outChannel = exchange.send(new HttpResponseHeader(200), (int) file.length());
          outChannel.flush(); // forces to write header FOR TEST PURPOSES ONLY
          QAUtil.sleep(500); // FOR TEST PURPOSES ONLY
         
          RandomAccessFile raf = new RandomAccessFile(file, "r");
          ReadableByteChannel fc = raf.getChannel();
           
          ByteBuffer copyBuffer = ByteBuffer.allocate(4096);
            
          int read = 0;
          while (read >= 0) {
             read = fc.read(copyBuffer);
             copyBuffer.flip();
               
             if (read > 0) {
                int size = outChannel.write(copyBuffer);
                written.addAndGet(size);
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

          BodyDataSink outChannel = exchange.send(new HttpResponseHeader(200), (int) file.length());
          outChannel.flush(); // forces to write header FOR TEST PURPOSES ONLY
          QAUtil.sleep(500); // FOR TEST PURPOSES ONLY
         
          RandomAccessFile raf = new RandomAccessFile(file, "r");
          ReadableByteChannel fc = raf.getChannel();
           
          ByteBuffer copyBuffer = ByteBuffer.allocate(4096);
            
          int read = 0;
          while (read >= 0) {
             read = fc.read(copyBuffer);
             copyBuffer.flip();
               
             if (read > 0) {
                int size = outChannel.write(copyBuffer);
                written.addAndGet(size);
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

          BodyDataSink outChannel = exchange.send(new HttpResponseHeader(200), (int) file.length());
          outChannel.flush(); // forces to write header FOR TEST PURPOSES ONLY
          QAUtil.sleep(500); // FOR TEST PURPOSES ONLY
         
          RandomAccessFile raf = new RandomAccessFile(file, "r");
          ReadableByteChannel fc = raf.getChannel();
           
          ByteBuffer copyBuffer = ByteBuffer.allocate(4096);
            
          int read = 0;
          while (read >= 0) {
             read = fc.read(copyBuffer);
             copyBuffer.flip();
               
             if (read > 0) {
                int size = outChannel.write(copyBuffer);
                written.addAndGet(size);
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

     * @see java.nio.ByteBuffer
     */
    public int read(ByteBuffer buffer) throws IOException, BadDescriptorException {
        checkOpen();
       
        ReadableByteChannel readChannel = (ReadableByteChannel) channel;
        int bytesRead = 0;
        bytesRead = readChannel.read(buffer);

        return bytesRead;
    }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    public NPOIFSFileSystem(InputStream stream)
        throws IOException
    {
        this(false);
       
        ReadableByteChannel channel = null;
        boolean success = false;
       
        try {
           // Turn our InputStream into something NIO based
           channel = Channels.newChannel(stream);
          
           // Get the header
           ByteBuffer headerBuffer = ByteBuffer.allocate(POIFSConstants.SMALLER_BIG_BLOCK_SIZE);
           IOUtils.readFully(channel, headerBuffer);
          
           // Have the header processed
           _header = new HeaderBlock(headerBuffer);
          
           // Sanity check the block count
           BlockAllocationTableReader.sanityCheckBlockCount(_header.getBATCount());
  
           // We need to buffer the whole file into memory when
           //  working with an InputStream.
           // The max possible size is when each BAT block entry is used
           int maxSize = BATBlock.calculateMaximumSize(_header);
           ByteBuffer data = ByteBuffer.allocate(maxSize);
           // Copy in the header
           headerBuffer.position(0);
           data.put(headerBuffer);
           data.position(headerBuffer.capacity());
           // Now read the rest of the stream
           IOUtils.readFully(channel, data);
           success = true;
          
           // Turn it into a DataSource
           _data = new ByteArrayBackedDataSource(data.array(), data.position());
        } finally {
           // As per the constructor contract, always close the stream
           if(channel != null)
              channel.close();
           closeInputStream(stream, success);
        }
       
        // Now process the various entries
        readCoreContents();
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    _log.info("Verified events: " + _srcEvents.size());
  }

  public void readDataAtDestination() throws InterruptedException, IOException
  {
    final ReadableByteChannel readChannel1 =
        Channels.newChannel(new ByteArrayInputStream(_srcByteStr.toByteArray()));
    final AtomicInteger eventsRead1 = new AtomicInteger(-1);
    final AtomicBoolean hasError1 = new AtomicBoolean(false);

    _log.info("Reading events on client side");
    //run the read in a separate thread in case it hangs
    Thread readThread1 = new Thread(new Runnable()
    {
      @Override
      public void run()
      {
        try
        {
          eventsRead1.set(_destBuf.readEvents(readChannel1, _destBufStats));
        }
        catch (InvalidEventException e)
        {
          _log.error("readEvents error: " + e.getMessage(), e);
          hasError1.set(true);
        }
      }
    }, "readEvents" );
    readThread1.setDaemon(true);
    readThread1.start();

    final long timeout = _debuggingMode ? 100000000 : 1000;
    readThread1.join(timeout);
    readChannel1.close();

    //smoke tests
    Assert.assertTrue(!readThread1.isAlive());
    Assert.assertEquals(_expectDestReadError, hasError1.get());
    if (!_expectDestReadError) Assert.assertEquals(_numStreamedEvents, eventsRead1.get());
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

    {
      cpEventBytes = new byte[event.getRawBytes().limit()];
      eventBuf.get(cpEventBytes);
    }
    ByteArrayInputStream cpIs = new ByteArrayInputStream(cpEventBytes);
    ReadableByteChannel cpRbc = Channels.newChannel(cpIs);
    int ecnt = readEvents(cpRbc);

    return ecnt > 0;
  }
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

      LOG.debug("error event:" + errorEvent.toString());
    }

    errorEvent.getRawBytes().get(errorEventBytes);
    ByteArrayInputStream errIs = new ByteArrayInputStream(errorEventBytes);
    ReadableByteChannel errRbc = Channels.newChannel(errIs);

    boolean success = false;
    int retryCounter = 0;
    while (!success && retryCounter < 10)
    {
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

        _log.debug("checkpoint event:" + cpEvent.toString());
      }

      cpEvent.getRawBytes().get(cpEventBytes);
      ByteArrayInputStream cpIs = new ByteArrayInputStream(cpEventBytes);
      ReadableByteChannel cpRbc = Channels.newChannel(cpIs);

      UnifiedClientStats unifiedClientStats = _sourcesConn.getUnifiedClientStats();
      sendHeartbeat(unifiedClientStats);
      int ecnt = eventBuffer.readEvents(cpRbc);
View Full Code Here

Examples of java.nio.channels.ReadableByteChannel

     * Dispose of this <code>InputStreamImageDataProvider</code> and its
     * resources.
     */
    public synchronized void dispose() {
        if ( m_channel != null ) {
            final ReadableByteChannel temp = m_channel;
            m_channel = null;
            try {
                temp.close();
            }
            catch ( IOException e ) {
                e.printStackTrace();
            }
        }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.