Package java.nio.channels

Examples of java.nio.channels.WritableByteChannel


            120000, 500000, 1024, 500, AllocationPolicy.HEAP_MEMORY, QueuePolicy.OVERWRITE_ON_WRITE,
            AssertLevel.ALL));

    final Checkpoint cp = Checkpoint.createOnlineConsumptionCheckpoint(1000);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    final WritableByteChannel ochannel = Channels.newChannel(baos);
    final AtomicBoolean hasError = new AtomicBoolean(false);
    final AtomicInteger num = new AtomicInteger(0);
    final AtomicBoolean genComplete = new AtomicBoolean(false);
    UncaughtExceptionTrackingThread streamThread = new UncaughtExceptionTrackingThread(new Runnable()
    {
View Full Code Here


    catch (Exception e1)
    {
      fail("Not supposed to throw exception");
    }
    //System.out.println(e);
    WritableByteChannel writeChannel = null;
    File directory = new File(".");
    File writeFile = File.createTempFile("test", ".dbus", directory);
    writeChannel = Utils.openChannel(writeFile, true);
    e.writeTo(writeChannel, Encoding.JSON);
    writeChannel.close();
    writeFile.delete();
  }
View Full Code Here

    DbusEventFactory.serializeEvent(new DbusEventKey(1L), serializationBuffer, eventInfo);
    DbusEventInternalReadable event1 = _eventV1Factory.createReadOnlyDbusEventFromBuffer(serializationBuffer, 0);
    assertTrue("event crc correct", event1.isValid());
    //test JSON_PLAIN_VALUE
    ByteArrayOutputStream jsonOut = new ByteArrayOutputStream();
    WritableByteChannel jsonOutChannel = Channels.newChannel(jsonOut);
    event1.writeTo(jsonOutChannel, Encoding.JSON_PLAIN_VALUE);

    byte[] jsonBytes = jsonOut.toByteArray();
    String jsonString = new String(jsonBytes);
View Full Code Here

  @Test
  public void testAppendToEventBuffer_many() throws Exception
  {
    ByteArrayOutputStream jsonOut = new ByteArrayOutputStream();
    ByteBuffer serializationBuffer = ByteBuffer.allocate(1000).order(_eventV1Factory.getByteOrder());
    WritableByteChannel jsonOutChannel = Channels.newChannel(jsonOut);
    for (int i = 0; i < 10; ++i)
    {
      int savePosition = serializationBuffer.position();
      String valueStr = "eventValue" + i;
      DbusEventInfo eventInfo = new DbusEventInfo(DbusOpcode.UPSERT, 0L, (short)0, (short)(i + 3), 4L + i, (short)(5 + i),
View Full Code Here

    assertEquals("Get DbusEventKey",stringKey.getBytes(Charset.defaultCharset()), ((DbusEventInternalReadable)e).getDbusEventKey().getStringKeyInBytes());

    // test both string-key and trace-enabled portions of writeTo():
    try
    {
      WritableByteChannel writeChannel = null;
      File directory = new File(".");
      File writeFile = File.createTempFile("test", ".dbus", directory);
      writeChannel = Utils.openChannel(writeFile, true);
      e.writeTo(writeChannel, Encoding.JSON);
      writeChannel.close();
      writeFile.delete();
    }
    catch (Exception e1)
    {
      fail("Unexpected exception writing string-key event to channel: " + e1.getMessage());
View Full Code Here

                                                    DbusEventsStatisticsCollector stats)
      throws ScnNotFoundException, OffsetNotFoundException, IOException
  {
    ChannelBuffer tmpBuf = ChannelBuffers.buffer(new DbusEventV1Factory().getByteOrder(), maxSize);
    OutputStream tmpOS = new ChannelBufferOutputStream(tmpBuf);
    WritableByteChannel tmpChannel = java.nio.channels.Channels.newChannel(tmpOS);

    StreamEventsArgs args = new StreamEventsArgs(maxSize).setStatsCollector(stats);

    buf.streamEvents(cp, tmpChannel, args);
    tmpChannel.close();
    return tmpBuf;
  }
View Full Code Here

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

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

      assertTrue("invalid event", 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);
    }
    byte[] writeBytes = oStream.toByteArray();
View Full Code Here

    //      [ H=Gen:1,Ofs:893, T=Gen:2,Ofs:561, L=9558 ]
    // head moves to first window after 561: 61 + 2 * 416 = 893 > 561

    //Set up the ReadChannel with new events
    ByteArrayOutputStream oStream = new ByteArrayOutputStream();
    WritableByteChannel oChannel = Channels.newChannel(oStream);

    for (DbusEvent e : events)
    {
      assertTrue("invalid event", e.isValid());
      ((DbusEventInternalReadable)e).writeTo(oChannel,Encoding.BINARY);
View Full Code Here

      Checkpoint cp = new Checkpoint();
      cp.setFlexible();

      ByteArrayOutputStream baos = new ByteArrayOutputStream();

      WritableByteChannel writeChannel = Channels.newChannel(baos);
      //File directory = new File(".");
      //File writeFile = File.createTempFile("test", ".dbus", directory);
      int streamedEvents = 0;

      final DbusEventsStatisticsCollector streamStats =
          new DbusEventsStatisticsCollector(1, "stream", true, false, null);
      //writeChannel = Utils.openChannel(writeFile, true);
      StreamEventsArgs args = new StreamEventsArgs(batchFetchSize).setStatsCollector(streamStats);
      streamedEvents = dbuf.streamEvents(cp, writeChannel, args).getNumEventsStreamed();

      writeChannel.close();
      final byte[] eventBytes = baos.toByteArray();
      Assert.assertTrue(eventBytes.length > 0);
      Assert.assertTrue(streamedEvents > 0);

      final DbusEventsStatisticsCollector inputStats =
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.