/** * Write bytes into the byte stream. * @param bytes bytes to be written */ public void write(byte[] bytes) { writeInteger32ToByteArray(bytes.length); writeUnderHandler(bytes); alignStream(); }
/** * @param timestamp the timestamp to be written */ public void write(Date timestamp) { writeInteger64ToByteArray(javaToNtpTimeStamp(timestamp.getTime())); }
/** * Convert the arguments into a byte array. * Used internally only. * @param stream where to write the arguments to */ private void computeArgumentsByteArray(final OSCJavaToByteArrayConverter stream) { stream.write(','); stream.writeTypes(arguments); for (final Object argument : arguments) { stream.write(argument); } }
/** * Write types for the arguments. * @param arguments the arguments to an OSCMessage */ public void writeTypes(Collection<Object> arguments) { writeTypesArray(arguments); // we always need to terminate with a zero, // even if (especially when) the stream is already aligned. stream.write(0); // align the stream with padded bytes alignStream(); }
/** * Write a string into the byte stream. * @param aString the string to be written */ public void write(String aString) { final byte[] stringBytes = aString.getBytes(charset); writeUnderHandler(stringBytes); stream.write(0); alignStream(); }
/** * Generate a representation of this packet conforming to the * the OSC byte stream specification. Used Internally. */ private byte[] computeByteArray() { final OSCJavaToByteArrayConverter stream = new OSCJavaToByteArrayConverter(); stream.setCharset(charset); return computeByteArray(stream); }
@SuppressWarnings("unchecked") final Collection<Object> theArray = (Collection<Object>) anObject; for (final Object entry : theArray) { write(entry); write((Float) anObject); } else if (anObject instanceof Double) { write((Double) anObject); } else if (anObject instanceof String) { write((String) anObject); } else if (anObject instanceof byte[]) { write((byte[]) anObject); } else if (anObject instanceof Character) { write((Character) anObject); } else if (anObject instanceof Integer) { write((Integer) anObject); } else if (anObject instanceof Long) { write((Long) anObject); } else if (anObject instanceof Date) { write((Date) anObject); } else if (!isNoDataObject(anObject)) { throw new UnsupportedOperationException("Do not know how to write an object of class: " + anObject.getClass());
@Override protected byte[] computeByteArray(final OSCJavaToByteArrayConverter stream) { stream.write("#bundle"); computeTimeTagByteArray(stream); byte[] packetBytes; for (final OSCPacket pkg : packets) { packetBytes = pkg.getByteArray(); stream.write(packetBytes); } return stream.toByteArray(); } }
writeTypesArray(collArg); writeType(argument.getClass());
/** * Write an integer into the byte stream. * @param anInt the integer to be written */ public void write(int anInt) { writeInteger32ToByteArray(anInt); }
/** * @param aLong the double precision integer to be written */ public void write(Long aLong) { writeInteger64ToByteArray(aLong); }
/** * Convert the address into a byte array. * Used internally only. * @param stream where to write the address to */ private void computeAddressByteArray(final OSCJavaToByteArrayConverter stream) { stream.write(address); }
/** * Write a char into the byte stream, and ensure it is 4 byte aligned again. * @param aChar the character to be written */ public void write(Character aChar) { stream.write((char) aChar); alignStream(); }
@Override protected byte[] computeByteArray(final OSCJavaToByteArrayConverter stream) { computeAddressByteArray(stream); computeArgumentsByteArray(stream); return stream.toByteArray(); }
/** * @param anInt the integer to be written */ public void write(Integer anInt) { writeInteger32ToByteArray(anInt); }
/** * Write a double into the byte stream (8 bytes). * @param aDouble double precision floating point number to be written */ public void write(Double aDouble) { writeInteger64ToByteArray(Double.doubleToRawLongBits(aDouble)); }
/** * Convert the time-tag (a Java Date) into the OSC byte stream. * Used Internally. * @param stream where to write the time-tag to */ private void computeTimeTagByteArray(final OSCJavaToByteArrayConverter stream) { if ((null == timestamp) || (timestamp.equals(TIMESTAMP_IMMEDIATE))) { stream.write((int) 0); stream.write((int) 1); return; } final long millisecs = timestamp.getTime(); final long secsSince1970 = (long) (millisecs / 1000); final long secs = secsSince1970 + SECONDS_FROM_1900_TO_1970; // this line was cribbed from jakarta commons-net's NTP TimeStamp code final long fraction = ((millisecs % 1000) * 0x100000000L) / 1000; stream.write((int) secs); stream.write((int) fraction); }
/** * Write a float into the byte stream. * @param aFloat floating point number to be written */ public void write(Float aFloat) { writeInteger32ToByteArray(Float.floatToIntBits(aFloat)); }