public ByteBuf add( String str ) { this.add( Byt.bytes( str ) ); return this; }
public ByteBuf add( String str ) { this.add( Byt.bytes( str ) ); return this; }
public ByteBuf add( String str ) { this.add( Byt.bytes( str ) ); return this; }
@Override public Map<String, String> loadAllByKeys(Collection<String> keys) { Set<String> keySet = new TreeSet<>(keys); List<byte[]> byteKeys = new ArrayList<>(); for (String key : keySet) { byte[] bKey = bytes(key); byteKeys.add(bKey); } final Map<byte[], byte[]> map = store.loadAllByKeys(byteKeys); final Map<String, String> results = new LinkedHashMap<>(); for (Map.Entry<byte[], byte[]> entry : map.entrySet()) { results.put(toString(entry.getKey()), toString(entry.getValue())); } return results; }
@Override public Map<String, String> loadAllByKeys(Collection<String> keys) { Set<String> keySet = new TreeSet<>(keys); List<byte[]> byteKeys = new ArrayList<>(); for (String key : keySet) { byte[] bKey = bytes(key); byteKeys.add(bKey); } final Map<byte[], byte[]> map = store.loadAllByKeys(byteKeys); final Map<String, String> results = new LinkedHashMap<>(); for (Map.Entry<byte[], byte[]> entry : map.entrySet()) { results.put(toString(entry.getKey()), toString(entry.getValue())); } return results; }
@Override public Map<String, String> loadAllByKeys(Collection<String> keys) { Set<String> keySet = new TreeSet<>(keys); List<byte[]> byteKeys = new ArrayList<>(); for (String key : keySet) { byte[] bKey = bytes(key); byteKeys.add(bKey); } final Map<byte[], byte[]> map = store.loadAllByKeys(byteKeys); final Map<String, String> results = new LinkedHashMap<>(); for (Map.Entry<byte[], byte[]> entry : map.entrySet()) { results.put(toString(entry.getKey()), toString(entry.getValue())); } return results; }
@Override public void writeMediumString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedShort( bytes.length ); this.add( bytes ); }
@Override public void writeLargeString( String s ) { final byte[] bytes = Byt.bytes( s ); this.add( bytes.length ); this.add( bytes ); }
@Override public void writeSmallString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedByte( ( short ) bytes.length ); this.add( bytes ); }
@Override public void writeSmallString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedByte( ( short ) bytes.length ); this.add( bytes ); }
@Override public void writeLargeString( String s ) { final byte[] bytes = Byt.bytes( s ); this.add( bytes.length ); this.add( bytes ); }
@Override public void writeMediumString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedShort( bytes.length ); this.add( bytes ); }
@Override public void writeLargeString( String s ) { final byte[] bytes = Byt.bytes( s ); this.add( bytes.length ); this.add( bytes ); }
@Override public void writeSmallString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedByte( ( short ) bytes.length ); this.add( bytes ); }
@Override public void writeMediumString( String s ) { final byte[] bytes = Byt.bytes( s ); this.addUnsignedShort( bytes.length ); this.add( bytes ); }
@Test public void splitThisByTabOrSpace() { byte[] letters = bytes( "This\tis a string" ); byte[][] splitted = ByteScanner.splitExact( letters, 10, '\t', ' ' ); assertEquals( 4, splitted.length ); assertArrayEquals( bytes( "This" ), splitted[ 0 ] ); assertArrayEquals( bytes( "is" ), splitted[ 1 ] ); assertArrayEquals( bytes( "a" ), splitted[ 2 ] ); assertArrayEquals( bytes( "string" ), splitted[ 3 ] ); assertArrayEquals( new byte[][]{ bytes( "This" ), bytes( "is" ), bytes( "a" ), bytes( "string" ) }, splitted ); }
@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 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" ) ); }
@Test ( expected = Exceptions.SoftenedException.class ) public void testExact2TooSmall() { ByteBuf buf = ByteBuf.createExact( 22 ); 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" ); }
@Test public void testByteCopyIntoCharArray() { char[] charArray = new char[ 1000 ]; byte[] bytes = Byt.bytes( "0123456789000" ); Chr._idx( charArray, 0, bytes ); boolean ok = true; char ch = charArray[ 0 ]; ok |= ch == '0' || die( " not '0'" ); ch = charArray[ 9 ]; ok |= ch == '9' || die( " not '9'" + ch ); Chr._idx( charArray, 100, bytes, 0, 3 ); ch = charArray[ 100 ]; ok |= ch == '0' || die( " not '0' " + ch ); ch = charArray[ 101 ]; ok |= ch == '1' || die( " not '1' " + ch ); ch = charArray[ 102 ]; ok |= ch == '2' || die( " not '2' " + ch ); Chr._idx( charArray, 200, bytes, 3, 6 ); ch = charArray[ 200 ]; ok |= ch == '3' || die( " not '3' " + ch ); ch = charArray[ 201 ]; ok |= ch == '4' || die( " not '4' " + ch ); ch = charArray[ 202 ]; ok |= ch == '5' || die( " not '5' " + ch ); }