msg_size = SUtil.bytesToInt(asize);
msg_size = SUtil.bytesToInt(asize);
/** * Create broadcast address according to prefix length. */ protected InetAddress createBroadcastAddress(InetAddress address, short prefixlen) { try { // InetAddress iadr = SUtil.getInet4Address(); byte[] byinet = address.getAddress(); int hostbits = 32-prefixlen; int mask = (int)Math.pow(2, hostbits)-1; int iinet = SUtil.bytesToInt(byinet); int badr = iinet | mask; return InetAddress.getByAddress(SUtil.intToBytes(badr)); } catch(Exception e) { throw new RuntimeException(e); } }
int len = SUtil.bytesToInt(buf); ret = new byte[len]; GZIPInputStream gzis = new GZIPInputStream(bais);
/** * Create broadcast address according to prefix length. */ protected InetAddress createBroadcastAddress(InetAddress address, short prefixlen) { try { // InetAddress iadr = SUtil.getInet4Address(); byte[] byinet = address.getAddress(); int hostbits = 32-prefixlen; int mask = (int)Math.pow(2, hostbits)-1; int iinet = SUtil.bytesToInt(byinet); int badr = iinet | mask; return InetAddress.getByAddress(SUtil.intToBytes(badr)); } catch(Exception e) { throw new RuntimeException(e); } }
int len = SUtil.bytesToInt(buf); ret = new byte[len]; GZIPInputStream gzis = new GZIPInputStream(bais);
msg_size = SUtil.bytesToInt(asize);
/** * Create broadcast address according to prefix length. */ protected InetAddress createBroadcastAddress(InetAddress address, short prefixlen) { try { // InetAddress iadr = SUtil.getInet4Address(); byte[] byinet = address.getAddress(); int hostbits = 32-prefixlen; int mask = (int)Math.pow(2, hostbits)-1; int iinet = SUtil.bytesToInt(byinet); int badr = iinet | mask; return InetAddress.getByAddress(SUtil.intToBytes(badr)); } catch(Exception e) { throw new RuntimeException(e); } }
/** * Read a string from the given stream. * @param in The input stream. * @return The string. * @throws IOException when the stream is closed. */ public static String readString(InputStream in) throws IOException { byte[] len = readData(in, 4); int length = SUtil.bytesToInt(len); byte[] buffer = readData(in, length); return new String(buffer, "UTF-8"); }
int len = SUtil.bytesToInt(buf); ret = new byte[len]; GZIPInputStream gzis = new GZIPInputStream(bais);
/** * */ protected static void testIntByteConversion() { Random rnd = new Random(123); for(int i=1; i<10000000; i++) { int val = rnd.nextInt(Integer.MAX_VALUE); if(i%2==0) // Test negative values too. { val = -val; } byte[] bytes = intToBytes(val); int val2 = bytesToInt(bytes); if(val!=val2) { throw new RuntimeException("Failed: "+val+", "+val2+", "+arrayToString(bytes)); } // System.out.println("Converted: "+val+", "+arrayToString(bytes)); } }
int ad = SUtil.bytesToInt(addr.getAddress()); ad >>>= 32-prefixlen; ad <<= 32-prefixlen;
/** * Receive a message from a socket. * @param accept The socket. */ public byte[] read() throws IOException { byte[] ret = null; int msg_size = SUtil.bytesToInt(new byte[]{(byte)readByte(), (byte)readByte(), (byte)readByte(), (byte)readByte()}); if(msg_size>0) { ret = new byte[msg_size]; int count = 0; while(count<msg_size) { int bytes_read = is.read(ret, count, msg_size-count); if(bytes_read==-1) throw new IOException("Stream closed"); count += bytes_read; } } return ret; }
/** * Receive a message from a socket. * @param accept The socket. */ public byte[] read() throws IOException { byte[] ret = null; int msg_size = SUtil.bytesToInt(new byte[]{(byte)readByte(), (byte)readByte(), (byte)readByte(), (byte)readByte()}); if(msg_size>0) { ret = new byte[msg_size]; int count = 0; while(count<msg_size) { int bytes_read = is.read(ret, count, msg_size-count); if(bytes_read==-1) throw new IOException("Stream closed"); count += bytes_read; } } // else // { // System.out.println("0-message"); // } return ret; }
/** * Receive a message from a socket. * @param accept The socket. */ public byte[] read() throws IOException { byte[] ret = null; int msg_size = SUtil.bytesToInt(new byte[]{(byte)readByte(), (byte)readByte(), (byte)readByte(), (byte)readByte()}); if(msg_size>0) { ret = new byte[msg_size]; int count = 0; while(count<msg_size) { int bytes_read = is.read(ret, count, msg_size-count); if(bytes_read==-1) throw new IOException("Stream closed"); count += bytes_read; } } // else // { // System.out.println("0-message"); // } return ret; }
int length = SUtil.bytesToInt(len);
/** * Called when a single platform info is received from a peer relay server. */ public void handlePlatform(InputStream in) throws Exception { // Read target id (= peer url). String id = readString(in); // Read total message length. byte[] len = readData(in, 4); int length = SUtil.bytesToInt(len); // Read message and extract platform info content. byte[] buffer = readData(in, length-1); PlatformInfo info = (PlatformInfo)MapSendTask.decodeMessage(buffer, codecs, getClass().getClassLoader(), IErrorReporter.IGNORE); ICodec[] pcodecs = MapSendTask.getCodecs(buffer, codecs); PeerEntry peer = peers.addPeer(id, false); peer.updatePlatformInfo(info); if(info.getAwarenessInfo()!=null) { sendAwarenessInfos(info.getAwarenessInfo(), pcodecs, false); } }
int iinet = SUtil.bytesToInt(byinet); int prefix = iinet & mask;
int iinet = SUtil.bytesToInt(byinet); int prefix = iinet & mask;
int length = SUtil.bytesToInt(len);