Package java.nio

Examples of java.nio.Buffer


        // Write them out, read what we wrote and check it
        client.write(buffers);
        ByteBuffer readBuffer = ByteBuffer.allocate(1024);
        worker.read(readBuffer);
        readBuffer.flip();
        Buffer expected = ByteBuffer.allocate(1024).put(data).put(data).flip();
        assertEquals(expected, readBuffer);

        // Tidy-up
        worker.close();
        client.close();
View Full Code Here


        bs.write();
    }
    public void testBufferFieldReadUnchanged() {
        if (!Platform.HAS_BUFFERS) return;
        BufferStructure bs = new BufferStructure();
        Buffer b = ByteBuffer.allocateDirect(16);
        bs.buffer = b;
        bs.dbuffer = ((ByteBuffer)bs.buffer).asDoubleBuffer();
        bs.write();
        bs.read();
        assertEquals("Buffer field should be unchanged", b, bs.buffer);
View Full Code Here

         int chunkSize = 10; // 10K
         int chunkId = 0;

         CharBuffer cbuf = CharBuffer.allocate(1024 * chunkSize);
         while (bufferedReader.read(cbuf) >= 0) {
            Buffer buffer = cbuf.flip();
            String textChunk = buffer.toString();
            cache.put(textFile + (chunkId++), textChunk);
            cbuf.clear();
            if (chunkId % 100 == 0) System.out.printf("  Inserted %s chunks from %s into grid%n", chunkId, textFile);
         }
      } finally {
View Full Code Here

      }
  }

  private void intialState(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    checkStatus(h, buf, "intialState", 10, 10, true, 10, 0);
  }
View Full Code Here

    buf = factory.newInstance();
    checkStatus(h, buf, "intialState", 10, 10, true, 10, 0);
  }
  private void position(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    h.check(buf.position(1), buf,  "position: buf.position(1)");
    checkStatus(h, buf, "position", 10, 10, true, 9, 1);
    buf.position(10);
    checkStatus(h, buf, "position", 10, 10, false, 0, 10);

    // position can't be negative
    buf = factory.newInstance();
    try
      {
        buf.position(-1);
        h.check(false, "position: is negative");
      }
      catch(IllegalArgumentException iae)
      {
        h.check(true, "position: can't be negative");
      }

    // position can't be larger than limit
    buf = factory.newInstance();
    buf.limit(5);
    try
      {
        buf.position(6);
        h.check(false, "position: is larger than capacity");
      }
      catch(IllegalArgumentException iae)
      {
        h.check(true, "position: can't be larger than capacity");
View Full Code Here

        h.check(true, "position: can't be larger than capacity");
      }
  }
  private void mark(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    // mark at default position
    buf = factory.newInstance();
    h.check(buf.mark(), buf, "mark: buf.mark()");
    checkStatus(h, buf, "mark", 10, 10, true, 10, 0);
    buf.position(5);
    checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
    h.check(buf.reset(), buf, "mark: buf.reset()");
    checkStatus(h, buf, "mark", 10, 10, true, 10, 0);
    buf.position(6);
    checkStatus(h, buf, "mark", 10, 10, true, 4, 6);
    buf.reset();
    checkStatus(h, buf, "mark", 10, 10, true, 10, 0);

    // mark at specified position
    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
    buf.position(6);
    checkStatus(h, buf, "mark", 10, 10, true, 4, 6);
    buf.reset();
    checkStatus(h, buf, "mark", 10, 10, true, 5, 5);
    buf.position(7);
    checkStatus(h, buf, "mark", 10, 10, true, 3, 7);
    buf.reset();
    checkStatus(h, buf, "mark", 10, 10, true, 5, 5);

    // mark should be discarded if new position is smaller than mark
    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    buf.position(4);
    try
      {
        buf.reset();
        h.check(false, "mark: mark not invalidated");
      }
      catch(InvalidMarkException ime)
      {
        h.check(true, "mark: invalidated mark");
View Full Code Here

      }
    checkStatus(h, buf, "mark", 10, 10, true, 6, 4);
  }
  private void limit(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    buf.position(2);
    buf.mark();
    buf.position(3);
    h.check(buf.limit(4), buf, "limit: buf.limit(4)");
    checkStatus(h, buf, "limit", 10, 4, true, 1, 3);
    buf.reset();
    checkStatus(h, buf, "limit", 10, 4, true, 2, 2);

    // mark should be discarded if new limit is smaller than mark
    // and position should be set to new limit
    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    buf.position(6);
    buf.limit(4);
    checkStatus(h, buf, "limit", 10, 4, false, 0, 4);
    try
      {
        buf.reset();
        h.check(false, "limit: mark not invalidated");
      }
      catch(InvalidMarkException ime)
      {
        h.check(true, "limit: invalidated mark");
      }

    // limit can't be negative
    buf = factory.newInstance();
    try
      {
        buf.limit(-1);
        h.check(false, "limit: is negative");
      }
      catch(IllegalArgumentException iae)
      {
        h.check(true, "limit: can't be negative");
      }

    // limit can't be larger than capacity
    buf = factory.newInstance();
    try
      {
        buf.limit(11);
        h.check(false, "limit: is larger than capacity");
      }
      catch(IllegalArgumentException iae)
      {
        h.check(true, "limit: can't be larger than capacity");
View Full Code Here

        h.check(true, "limit: can't be larger than capacity");
      }
  }
  private void rewind(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    buf.position(6);
    buf.limit(9);
    h.check(buf.rewind(), buf, "rewind: buf.rewind()");
    checkStatus(h, buf, "rewind", 10, 9, true, 9, 0);
    try
      {
        buf.reset();
        h.check(false, "rewind: mark not invalidated");
     }
      catch(InvalidMarkException ime)
      {
        h.check(true, "rewind: invalidated mark");
View Full Code Here

        h.check(true, "rewind: invalidated mark");
      }
  }
  private void clear(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    buf.position(6);
    buf.limit(7);
    h.check(buf.clear(), buf, "clear: buf.clear()");
    checkStatus(h, buf, "clear", 10, 10, true, 10, 0);
    try
      {
        buf.reset();
        h.check(false, "clear: mark not invalidated");
      }
      catch(InvalidMarkException ime)
      {
        h.check(true, "clear: invalidated mark");
View Full Code Here

        h.check(true, "clear: invalidated mark");
      }
  }
  private void flip(TestHarness h, BufferFactory factory)
  {
    Buffer buf = null;

    buf = factory.newInstance();
    buf.position(5);
    buf.mark();
    buf.position(6);
    h.check(buf.flip(), buf, "flip: buf.flip()");
    checkStatus(h, buf, "flip", 10, 6, true, 6, 0);
    try
      {
        buf.reset();
        h.check(false, "flip: mark not invalidated");
      }
      catch(InvalidMarkException ime)
      {
        h.check(true, "flip: invalidated mark");
View Full Code Here

TOP

Related Classes of java.nio.Buffer

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.