Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


    int batchFetchSize = 5000;
    Checkpoint cp = new Checkpoint();
    cp.setWindowScn(minDbusEventBufferScn);
    cp.setWindowOffset(0);
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    WritableByteChannel writeChannel = null;
    File directory = new File(".");
    File writeFile = File.createTempFile("test", ".dbus", directory);
    try
    {
      writeChannel = Utils.openChannel(writeFile, true);
      StreamEventsArgs args = new StreamEventsArgs(batchFetchSize);
      dbuf.streamEvents(cp, writeChannel, args);
    }
    catch (ScnNotFoundException e)
    {
    }

    writeChannel.close();
    LOG.debug(writeFile.canRead());

    ReadableByteChannel readChannel = Utils.openChannel(writeFile, false);
    DbusEventBuffer checkDbusEventBuffer =
        new DbusEventBuffer(getConfig(50000, DbusEventBuffer.Config.DEFAULT_INDIVIDUAL_BUFFER_SIZE,
View Full Code Here


  protected boolean streamWriterReader(DbusEventBuffer prodBuffer,int batchSize,Checkpoint cp,String filename,DbusEventBuffer readBuffer,Vector<Long> seenScn,DbusEventsStatisticsCollector stats)
  {
    try
    {
      WritableByteChannel writeChannel = null;
      File directory = new File(".");
      File writeFile = File.createTempFile(filename, ".dbus", directory);
      int numStreamedEvents = 0;
      try
      {
        writeChannel = Utils.openChannel(writeFile, true);
        StreamEventsArgs args = new StreamEventsArgs(batchSize);

        numStreamedEvents = prodBuffer.streamEvents(cp, writeChannel, args).getNumEventsStreamed();

      }
      catch (ScnNotFoundException e)
      {
        e.printStackTrace();
        return false;
      }

      writeChannel.close();

      ReadableByteChannel readChannel = Utils.openChannel(writeFile, false);
      int readEvents = readBuffer.readEvents(readChannel,null,stats);

      writeFile.delete();
View Full Code Here

    Assert.assertEquals(W * E, statsCollector.getTotalStats().getNumDataEvents());

    File tmpFile= File.createTempFile(TestDbusEventBuffer.class.getSimpleName(), ".tmp");
    tmpFile.deleteOnExit();
    OutputStream outStream = new FileOutputStream(tmpFile);
    WritableByteChannel outChannel = Channels.newChannel(outStream);

    //stream events
    DbusEventsStatisticsCollector outStatsCollector = new DbusEventsStatisticsCollector(1, "out", true, false, null);
    Checkpoint cp = new Checkpoint();
    cp.setFlexible();
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    ErrorCountingAppender errorCountAppender = new ErrorCountingAppender();
    errorCountAppender.setName("errorCountAppender");
    DbusEventSerializable.LOG.addAppender(errorCountAppender);
    Level oldLevel = DbusEventSerializable.LOG.getLevel();
    //ensure ERROR log level because gradle likes to change it
    DbusEventSerializable.LOG.setLevel(Level.ERROR);

    int errNum = errorCountAppender.getErrorNum();
    StreamEventsArgs args = new StreamEventsArgs(10000).setStatsCollector(outStatsCollector);
    int written = buf.streamEvents(cp, outChannel, args).getNumEventsStreamed();

    Assert.assertEquals(errorCountAppender, DbusEventSerializable.LOG.getAppender("errorCountAppender"));
    Assert.assertEquals(W * (E + 1), written);
    Assert.assertEquals(errNum, errorCountAppender.getErrorNum());

    //close the channel to force an error for streamEvents
    outStream.close();
    outChannel.close();

    cp = new Checkpoint();
    cp.setFlexible();
    cp.setConsumptionMode(DbusClientMode.ONLINE_CONSUMPTION);
    errNum = errorCountAppender.getErrorNum();
View Full Code Here

      assertTrue("invalid event #" + i, e.isValid());
      LOG.info("DbusEvent " + i + " " + e);
    }
    // set up the ReadChannel with 2 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 3; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

      assertTrue("invalid event #" + i, e.isValid());
    }

    // Set up the ReadChannel with 2 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 6; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

      assertTrue("invalid event #" + i, e.isValid());
    }

    // Set up the ReadChannel with 2 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 6; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

      assertTrue("invalid event #" + i, e.isValid());
    }

    // Set up the ReadChannel with 2 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 2; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

      LOG.info("DbusEvent " + i + " " + e);
    }

    // Set up the ReadChannel with 2 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 3; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

      assertTrue("invalid event #" + i, e.isValid());
    }

    // Set up the ReadChannel with 6 events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);
    for (int i = 0; i < 6; ++i)
    {
      ((DbusEventInternalReadable)events.get(i)).writeTo(oChannel,Encoding.BINARY);
    }
View Full Code Here

    }

    public static void fastChannelCopy(final InputStream in, final OutputStream out) throws IOException {

        final ReadableByteChannel src = Channels.newChannel(in);
        final WritableByteChannel dest = Channels.newChannel(out);

        try {
            final ByteBuffer buffer = ByteBuffer.allocate(8 * 1024);
            while (src.read(buffer) != -1) {
                buffer.flip();
                dest.write(buffer);
                buffer.compact();
            }
            buffer.flip();

            while (buffer.hasRemaining()) {
                dest.write(buffer);
            }
        } finally {
            safeClose(src);
            safeClose(dest);
        }
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.