List of usage examples for java.nio ByteBuffer rewind
public final Buffer rewind()
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("java2s!"); bb.rewind(); byte[] dst = new byte[BSIZE]; bb.get(dst);/* w w w. ja v a 2 s. co m*/ System.out.println(Arrays.toString(dst)); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asLongBuffer().put(99472342341142L); bb.rewind(); System.out.println(bb.getLong()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asShortBuffer().put((short) 471142); bb.rewind(); System.out.println(bb.getShort()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("java2s.com"); bb.rewind(); char c;/*from w ww . java2s .co m*/ while ((c = bb.getChar()) != 0) System.out.print(c + " "); System.out.println(); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf);// w w w . ja va 2 s . co m mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:Main.java
public static void main(String args[]) throws Exception { FileInputStream fIn = new FileInputStream("test.txt"); FileChannel fChan = fIn.getChannel(); long fSize = fChan.size(); ByteBuffer mBuf = ByteBuffer.allocate((int) fSize); fChan.read(mBuf, 10);//from www .j a v a 2 s.com mBuf.rewind(); for (int i = 0; i < fSize; i++) { System.out.print((char) mBuf.get()); } fChan.close(); fIn.close(); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[] { 0, 0, 0, 0, 0, 0, 0, 'a' }); bb.rewind(); System.out.println("Byte Buffer"); while (bb.hasRemaining()) System.out.println(bb.position() + " -> " + bb.get()); CharBuffer cb = ((ByteBuffer) bb.rewind()).asCharBuffer(); System.out.println("Char Buffer"); while (cb.hasRemaining()) System.out.println(cb.position() + " -> " + cb.get()); FloatBuffer fb = ((ByteBuffer) bb.rewind()).asFloatBuffer(); System.out.println("Float Buffer"); while (fb.hasRemaining()) System.out.println(fb.position() + " -> " + fb.get()); IntBuffer ib = ((ByteBuffer) bb.rewind()).asIntBuffer(); System.out.println("Int Buffer"); while (ib.hasRemaining()) System.out.println(ib.position() + " -> " + ib.get()); LongBuffer lb = ((ByteBuffer) bb.rewind()).asLongBuffer(); System.out.println("Long Buffer"); while (lb.hasRemaining()) System.out.println(lb.position() + " -> " + lb.get()); ShortBuffer sb = ((ByteBuffer) bb.rewind()).asShortBuffer(); System.out.println("Short Buffer"); while (sb.hasRemaining()) System.out.println(sb.position() + " -> " + sb.get()); DoubleBuffer db = ((ByteBuffer) bb.rewind()).asDoubleBuffer(); System.out.println("Double Buffer"); while (db.hasRemaining()) System.out.println(db.position() + " -> " + db.get()); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(BSIZE); bb.asCharBuffer().put("java2s!"); byte[] dst = new byte[BSIZE]; bb.rewind(); bb.get(dst, 0, 3);/*from ww w. ja v a 2s .c o m*/ System.out.println(Arrays.toString(dst)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ReadableByteChannel channel = new FileInputStream("infile.dat").getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(10); int numRead = 0; while (numRead >= 0) { buf.rewind(); numRead = channel.read(buf);// ww w . ja v a2s. c om buf.rewind(); for (int i = 0; i < numRead; i++) { byte b = buf.get(); } } }
From source file:Main.java
public static void main(String[] argv) throws Exception { ReadableByteChannel channel = new FileInputStream("infile").getChannel(); ByteBuffer buf = ByteBuffer.allocateDirect(10); int numRead = 0; while (numRead >= 0) { buf.rewind(); numRead = channel.read(buf);//w w w. j av a 2s.c o m buf.rewind(); for (int i = 0; i < numRead; i++) { byte b = buf.get(); } } }