/** * Get the prolog bytes. * Separated from data to avoid array copies. * Message service expects messages to be delivered in the form {prolog}{data}. * @return The prolog bytes. */ protected byte[] fetchProlog() { byte[] prolog = new byte[7+codecids.length+(seqnumber==null? 0: 4)]; prolog[0] = MESSAGE_TYPE_STREAM; prolog[1] = type; prolog[2] = (byte)codecids.length; System.arraycopy(codecids, 0, prolog, 3, codecids.length); byte[] strid = SUtil.intToBytes(streamid); for(int i=0; i<4; i++) prolog[i+3+codecids.length] = strid[i]; if(seqnumber!=null) { byte[] seqnum = SUtil.intToBytes(seqnumber.intValue()); for(int i=0; i<4; i++) prolog[i+7+codecids.length] = seqnum[i]; } return prolog; }
/** * Get the prolog bytes. * Separated from data to avoid array copies. * Message service expects messages to be delivered in the form {prolog}{data}. * @return The prolog bytes. */ protected byte[] fetchProlog() { byte[] prolog = new byte[7+codecids.length+(seqnumber==null? 0: 4)]; prolog[0] = MESSAGE_TYPE_STREAM; prolog[1] = type; prolog[2] = (byte)codecids.length; System.arraycopy(codecids, 0, prolog, 3, codecids.length); byte[] strid = SUtil.intToBytes(streamid); for(int i=0; i<4; i++) prolog[i+3+codecids.length] = strid[i]; if(seqnumber!=null) { byte[] seqnum = SUtil.intToBytes(seqnumber.intValue()); for(int i=0; i<4; i++) prolog[i+7+codecids.length] = seqnum[i]; } return prolog; }
prolog[2] = (byte)codecids.length; System.arraycopy(codecids, 0, prolog, 3, codecids.length); byte[] strid = SUtil.intToBytes(streamid); for(int i=0; i<4; i++) prolog[i+3+codecids.length] = strid[i]; if(seqnumber!=null) byte[] seqnum = SUtil.intToBytes(seqnumber.intValue()); for(int i=0; i<4; i++) prolog[i+7+codecids.length] = seqnum[i];
/** * Encode an object. * @param obj The object. * @throws IOException */ public static byte[] encodeBytes(byte[] val, ClassLoader classloader) { byte[] ret = (byte[])val; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(SUtil.intToBytes(val.length)); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(val); gzos.close(); ret = baos.toByteArray(); } catch(Exception e) { throw e instanceof RuntimeException? (RuntimeException)e: new RuntimeException(e); } return ret; }
/** * Encode an object. * @param obj The object. * @throws IOException */ public static byte[] encodeBytes(byte[] val, ClassLoader classloader) { byte[] ret = (byte[])val; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(SUtil.intToBytes(val.length)); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(val); gzos.close(); ret = baos.toByteArray(); } catch(Exception e) { throw e instanceof RuntimeException? (RuntimeException)e: new RuntimeException(e); } return ret; }
/** * Encode an object. * @param obj The object. * @throws IOException */ public static byte[] encodeBytes(byte[] val, ClassLoader classloader) { byte[] ret = (byte[])val; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); baos.write(SUtil.intToBytes(val.length)); GZIPOutputStream gzos = new GZIPOutputStream(baos); gzos.write(val); gzos.close(); ret = baos.toByteArray(); } catch(Exception e) { throw SUtil.throwUnchecked(e); } return ret; }
/** * 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); } }
/** * 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); } }
/** * 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); } }
/** * */ 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)); } }
sos.write(SUtil.intToBytes(prolog.length+data.length));
buffers.add(ByteBuffer.wrap(SUtil.intToBytes(prolog.length+data.length))); buffers.add(ByteBuffer.wrap(prolog)); buffers.add(ByteBuffer.wrap(data));
ad >>>= 32-prefixlen; ad <<= 32-prefixlen; ret = InetAddress.getByAddress(SUtil.intToBytes(ad));
buffers.add(ByteBuffer.wrap(SUtil.intToBytes(prolog.length+data.length))); buffers.add(ByteBuffer.wrap(prolog)); buffers.add(ByteBuffer.wrap(data));
byte[] bip = SUtil.intToBytes(iip); InetAddress address = InetAddress.getByAddress(bip); if(!send(data, address, getAgent().getPort()))
byte[] bip = SUtil.intToBytes(iip); InetAddress address = InetAddress.getByAddress(bip); if(!send(data, address, getAgent().getPort()))
byte[] bip = SUtil.intToBytes(iip); InetAddress address = InetAddress.getByAddress(bip); if(!send(data, address, getAgent().getPort()))
sendAcknowledgedMessage(createTask(StreamSendTask.CLOSE, SUtil.intToBytes(seqnumber), null, nonfunc), StreamSendTask.CLOSE) .addResultListener(new IResultListener<Object>()
sendAcknowledgedMessage(createTask(StreamSendTask.CLOSE, SUtil.intToBytes(seqnumber), null, nonfunc), StreamSendTask.CLOSE) .addResultListener(new IResultListener<Object>()
sendAcknowledgedMessage(createTask(StreamSendTask.CLOSE, SUtil.intToBytes(seqnumber), null, nonfunc), StreamSendTask.CLOSE) .addResultListener(new IResultListener<Object>()