Package java.nio.channels

Examples of java.nio.channels.ReadableByteChannel


      if (LOG.isDebugEnabled()) {
        LOG.debug("Have read input token of size " + inBuf.length
            + " for processing by saslServer.unwrap()");
      }
      inBuf = saslServer.unwrap(inBuf, 0, inBuf.length);
      ReadableByteChannel ch = Channels.newChannel(new ByteArrayInputStream(
          inBuf));
      // Read all RPCs contained in the inBuf, even partial ones
      while (true) {
        int count = -1;
        if (unwrappedDataLengthBuffer.remaining() > 0) {
View Full Code Here


     */
    public void outputReady(final NHttpServerConnection conn, final ContentEncoder encoder) {

        HttpContext context = conn.getContext();
        HttpResponse response = conn.getHttpResponse();
        ReadableByteChannel source = (ReadableByteChannel) context.getAttribute(RESPONSE_SOURCE_CHANNEL);
        ByteBuffer outbuf = (ByteBuffer) context.getAttribute(RESPONSE_BUFFER);

        try {
            int bytesRead = source.read(outbuf);
            if (bytesRead == -1 && outbuf.position() == 0) {
                encoder.complete();
            } else {
                outbuf.flip();
                encoder.write(outbuf);
                outbuf.compact();
            }

            if (encoder.isCompleted()) {
                source.close();
                if (!connStrategy.keepAlive(response, context)) {
                    conn.close();
                }
            }

View Full Code Here

     * @param encoder the encoder in use
     */
    public void outputReady(final NHttpClientConnection conn, final ContentEncoder encoder) {
        HttpContext context = conn.getContext();

        ReadableByteChannel source = (ReadableByteChannel) context.getAttribute(REQUEST_SOURCE_CHANNEL);
        ByteBuffer outbuf = (ByteBuffer) context.getAttribute(RESPONSE_BUFFER);

        try {
            int bytesRead = source.read(outbuf);
            if (bytesRead == -1) {
                encoder.complete();
            } else {
                outbuf.flip();
                encoder.write(outbuf);
                outbuf.compact();
            }

            if (encoder.isCompleted()) {
                source.close();
            }

        } catch (IOException e) {
            handleException("I/O Error : " + e.getMessage(), e, conn);
        }
View Full Code Here

                    }
                    logger.info("Receiving file " + fileEntry.getFileName());

                    FileChannel fileChannel = new FileOutputStream(new File(destinationDirPath,
                                                                            fileEntry.getFileName())).getChannel();
                    ReadableByteChannel channelIn = Channels.newChannel(inputStream);
                    fileChannel.transferFrom(channelIn, 0, fileEntry.getFileSizeBytes());
                    fileChannel.force(true);
                    fileChannel.close();

                    logger.info("Completed file " + fileEntry.getFileName());
View Full Code Here

  }

  protected static boolean isEqual(InputStream stream1, InputStream stream2)
          throws IOException {

      ReadableByteChannel channel1 = Channels.newChannel(stream1);
      ReadableByteChannel channel2 = Channels.newChannel(stream2);

      ByteBuffer buffer1 = ByteBuffer.allocateDirect(1024);
      ByteBuffer buffer2 = ByteBuffer.allocateDirect(1024);

      try {
          while (true) {

              int bytesReadFromStream1 = channel1.read(buffer1);
              int bytesReadFromStream2 = channel2.read(buffer2);

              if (bytesReadFromStream1 == -1 || bytesReadFromStream2 == -1) return bytesReadFromStream1 == bytesReadFromStream2;

              buffer1.flip();
              buffer2.flip();
View Full Code Here

  }

  private static boolean isEqual(InputStream stream1, InputStream stream2)
          throws IOException {

      ReadableByteChannel channel1 = Channels.newChannel(stream1);
      ReadableByteChannel channel2 = Channels.newChannel(stream2);

      ByteBuffer buffer1 = ByteBuffer.allocateDirect(1024);
      ByteBuffer buffer2 = ByteBuffer.allocateDirect(1024);

      try {
          while (true) {

              int bytesReadFromStream1 = channel1.read(buffer1);
              int bytesReadFromStream2 = channel2.read(buffer2);

              if (bytesReadFromStream1 == -1 || bytesReadFromStream2 == -1) return bytesReadFromStream1 == bytesReadFromStream2;

              buffer1.flip();
              buffer2.flip();
View Full Code Here

public class HttpDownloader {

    public void urlDownload(URL FromUrl, File ToFile) throws FileNotFoundException, IOException {
  //ToFile.deleteOnExit();
  //ToFile.createNewFile();
  ReadableByteChannel bc = Channels.newChannel(FromUrl.openStream());
  FileChannel fc = (new FileOutputStream(ToFile)).getChannel();
  int pos = 0;// ������� � �����
  int transferunit = 1024;// ����� ������������ �� 1024 ����
  int len;// ������� ������������ �� ����� ����
  while ((len = (int) fc.transferFrom(bc, (long) pos, (long) transferunit)) == transferunit) {
      pos += len;
  }
  bc.close();
  fc.close();
    }
View Full Code Here

      log.info("create some events");
      long windowScn = 100L;
      ByteBuffer serializationBuffer = addEvent(windowScn, srcId, relay1.getSchemaRegistryService().fetchSchemaIdForSourceNameAndVersion(srcs[0], 2).getByteArray(),
          pId, DbusEventFactory.DBUS_EVENT_V2);
      ReadableByteChannel channel = Channels.newChannel(new ByteBufferInputStream(serializationBuffer));
      int readEvents = buf.readEvents(channel);
      log.info("successfully read in " + readEvents + " events ");
      channel.close();

      windowScn = 101L;
      serializationBuffer = addEvent(windowScn, srcId, relay1.getSchemaRegistryService().fetchSchemaIdForSourceNameAndVersion(srcs[0], 2).getByteArray(),
          pId, DbusEventFactory.DBUS_EVENT_V1);
      channel = Channels.newChannel(new ByteBufferInputStream(serializationBuffer));
      readEvents = buf.readEvents(channel);
      log.info("successfully read in " + readEvents + " events ");
      channel.close();

      log.info("starting relay on port " + relayPort);
      r1.start();
      //TestUtil.sleep(10*1000);

 
View Full Code Here

      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }

    byte[] writeBytes = oStream.toByteArray();
    ByteArrayInputStream iStream = new ByteArrayInputStream(writeBytes);
    ReadableByteChannel rChannel = Channels.newChannel(iStream);
    try
    {
      dbusBuf.readEvents(rChannel);
    }
    catch (InvalidEventException ie)
View Full Code Here

    while ((!success) && (timer.getRemainingRetriesNum() > 0))
    {
      ByteArrayInputStream cpIs = new ByteArrayInputStream(
          eventBytes);
      ReadableByteChannel cpRbc = Channels.newChannel(cpIs);

      sendHeartbeat(unifiedClientStats);
      int ecnt = curState.getDataEventsBuffer().readEvents(cpRbc);
      if (ecnt <= 0) {
        _log.error("Not enough spece in the event buffer to add a control message :" + message);
View Full Code Here

TOP

Related Classes of java.nio.channels.ReadableByteChannel

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.