public String toString() { int len = len(); char[] chars = new char[ buffer.length ]; for ( int index = 0; index < chars.length; index++ ) { chars[ index ] = ( char ) buffer[ index ]; } return new String( chars, 0, len ); //return new String ( this.buffer, 0, len, StandardCharsets.UTF_8 ); }
public String toString() { int len = len(); char[] chars = new char[ buffer.length ]; for ( int index = 0; index < chars.length; index++ ) { chars[ index ] = ( char ) buffer[ index ]; } return new String( chars, 0, len ); //return new String ( this.buffer, 0, len, StandardCharsets.UTF_8 ); }
public String toString() { int len = len(); char[] chars = new char[ buffer.length ]; for ( int index = 0; index < chars.length; index++ ) { chars[ index ] = ( char ) buffer[ index ]; } return new String( chars, 0, len ); //return new String ( this.buffer, 0, len, StandardCharsets.UTF_8 ); }
ByteBuf buf = ByteBuf.createExact(8); //Add the short to the array buf.add((short)77); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the short back int value = idxShort(bytes, 0); worked |= buf.len() == 2 || die("short worked length = 2"); worked |= value == 77 || die("short worked value was 77");
ByteBuf buf = ByteBuf.createExact(8); //Add the char to the array buf.add('c'); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the char back int value = idxChar(bytes, 0); worked |= buf.len() == 2 || die("char worked length = 4"); worked |= value == 'c' || die("char worked value was 'c'");
ByteBuf buf = ByteBuf.createExact(8); //Add the byte to the array buf.add( (byte)33 ); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the byte back int value = idx(bytes, 0); worked |= buf.len() == 1 || die("byte worked length = 1"); worked |= value == 33 || die("byte worked value was 33");
ByteBuf buf = ByteBuf.createExact(8); //add the float buf.add(10.001f); byte[] bytes = buf.readAndReset(); boolean worked = true; worked |= buf.len() == 4 || die("Float worked"); //read the float float flt = idxFloat(bytes, 0); worked |= flt == 10.001f || die("Float worked");
ByteBuf buf = ByteBuf.createExact(8); //Add the int to the array buf.add(99); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the int back int value = idxInt(bytes, 0); worked |= buf.len() == 4 || die("Int worked length = 4"); worked |= value == 99 || die("Int worked value was 99");
int len = buf.len (); IO.write(connection.getOutputStream(), new String(buf.readForRecycle (), 0, len, StandardCharsets.UTF_8), IO.DEFAULT_CHARSET);
int len = buf.len(); IO.write( connection.getOutputStream(), new String( buf.readForRecycle(), 0, len, StandardCharsets.UTF_8 ), IO.DEFAULT_CHARSET );
int len = buf.len(); IO.write( connection.getOutputStream(), new String( buf.readForRecycle(), 0, len, StandardCharsets.UTF_8 ), IO.DEFAULT_CHARSET );
ByteBuf buf = ByteBuf.createExact(66); buf.add(bytes("0123456789\n")); buf.add("0123456789\n"); buf.add("0123456789\n"); buf.add("0123456789\n"); buf.add("0123456789\n"); buf.add("0123456END\n"); assertEquals(66, buf.len());
@Test public void testMe() { ByteBuf buf = new ByteBuf(); buf.add( bytes( "0123456789\n" ) ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456END\n" ); String out = new String( buf.readAndReset(), 0, buf.len() ); assertEquals( 66, buf.len() ); assertTrue( out.endsWith( "END\n" ) ); }
boolean worked = true; ByteBuf buf = ByteBuf.create(1); //Add the various to the array buf.add( (byte) 1 ); buf.add( (short) 2 ); buf.add( (char) 3 ); buf.add( 4 ); buf.add( (float) 5 ); buf.add( (long) 6 ); buf.add( (double)7 ); worked |= buf.len() == 29 || die("length = 29"); byte[] bytes = buf.readAndReset(); byte myByte; short myShort; char myChar; int myInt; float myFloat; long myLong; double myDouble;
@Test public void testExact() { ByteBuf buf = ByteBuf.createExact( 66 ); buf.add( bytes( "0123456789\n" ) ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456789\n" ); buf.add( "0123456END\n" ); String out = new String( buf.readAndReset() ); assertEquals( 66, buf.len() ); assertTrue( out.endsWith( "END\n" ) ); }
@Test public void floatTest() { ByteBuf buf = ByteBuf.createExact( 8 ); //addObject the float buf.add( 10.001f ); byte[] bytes = buf.readAndReset(); boolean worked = true; worked |= buf.len() == 4 || die( "Float worked" ); //read the float float flt = idxFloat( bytes, 0 ); worked |= flt == 10.001f || die( "Float worked" ); }
@Test public void byteTest() { ByteBuf buf = ByteBuf.createExact( 8 ); //Add the byte to the array buf.add( ( byte ) 33 ); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the byte back int value = idx( bytes, 0 ); worked |= buf.len() == 1 || die( "byte worked length = 1" ); worked |= value == 33 || die( "byte worked value was 33" ); }
@Test public void intTest() { ByteBuf buf = ByteBuf.createExact( 8 ); //Add the int to the array buf.add( 99 ); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the int back int value = idxInt( bytes, 0 ); worked |= buf.len() == 4 || die( "Int worked length = 4" ); worked |= value == 99 || die( "Int worked value was 99" ); }
@Test public void shortTest() { ByteBuf buf = ByteBuf.createExact( 8 ); //Add the short to the array buf.add( ( short ) 77 ); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the short back int value = idxShort( bytes, 0 ); worked |= buf.len() == 2 || die( "short worked length = 2" ); worked |= value == 77 || die( "short worked value was 77" ); }
@Test public void charTest() { ByteBuf buf = ByteBuf.createExact( 8 ); //Add the char to the array buf.add( 'c' ); byte[] bytes = buf.readAndReset(); boolean worked = true; //Read the char back int value = idxChar( bytes, 0 ); worked |= buf.len() == 2 || die( "char worked length = 4" ); worked |= value == 'c' || die( "char worked value was 'c'" ); }