public static int bytesToInt(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 4); return buf.getInt(); }
public static ByteBuffer expand(ByteBuffer buf) { int cap = buf.capacity(); if (cap <= 1000) { cap *= 10; } else if (cap <= 10000) { cap *= 5; } else { cap *= 2; } return expand(buf, cap); }
public static String buf2str(ByteBuffer buf) { return new String(buf2bytes(buf)); }
public static long bytesToLong(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 8); return buf.getLong(); }
public static ByteBuffer expand(ByteBuffer buf) { int cap = buf.capacity(); if (cap <= 1000) { cap *= 10; } else if (cap <= 10000) { cap *= 5; } else { cap *= 2; } return expand(buf, cap); }
public static int[] buf2ubytes(ByteBuffer buf) { byte[] bytes = buf2bytes(buf); int[] ubytes = new int[bytes.length]; for (int i = 0; i < bytes.length; i++) { ubytes[i] = Msc.ubyte(bytes[i]); } return ubytes; }
public static short bytesToShort(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 2); return buf.getShort(); }
public static byte[] toBytes(Object obj) { if (obj instanceof byte[]) { return (byte[]) obj; } else if (obj instanceof ByteBuffer) { return Bufs.buf2bytes((ByteBuffer) obj); } else if (obj instanceof InputStream) { return IO.loadBytes((InputStream) obj); } else if (obj instanceof File) { Res res = Res.from((File) obj); res.mustExist(); return res.getBytes(); } else if (obj instanceof Res) { Res res = (Res) obj; res.mustExist(); return res.getBytes(); } else { // this might be a Widget, so rendering it requires double toString: // U.str(obj); // 1. data binding and event processing return U.str(obj).getBytes(); // 2. actual rendering } }
public static int bytesToInt(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 4); return buf.getInt(); }
public static long bytesToLong(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 8); return buf.getLong(); }
public static short bytesToShort(String s) { ByteBuffer buf = Bufs.buf(s); U.must(buf.limit() == 2); return buf.getShort(); }