List of usage examples for java.nio ByteOrder LITTLE_ENDIAN
ByteOrder LITTLE_ENDIAN
To view the source code for java.nio ByteOrder LITTLE_ENDIAN.
Click Source Link
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer buf = ByteBuffer.allocate(10); buf.order(ByteOrder.LITTLE_ENDIAN); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer bbuf = ByteBuffer.allocate(10); int capacity = bbuf.capacity(); // 10 System.out.println(capacity); bbuf.order(ByteOrder.LITTLE_ENDIAN); bbuf.put("java2s.com".getBytes()); System.out.println(Arrays.toString(bbuf.array())); }
From source file:Main.java
public static void main(String[] argv) throws Exception { ByteBuffer bbuf = ByteBuffer.allocate(10); int capacity = bbuf.capacity(); // 10 System.out.println(capacity); bbuf.putShort(2, (short) 123); bbuf.order(ByteOrder.LITTLE_ENDIAN); ByteOrder byteOrder = bbuf.order(); System.out.println(byteOrder); }
From source file:Main.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.allocate(2); System.out.println("Default Byte Order: " + bb.order()); bb.putShort((short) 300); bb.flip();//w ww . j a v a 2 s .c o m showByteOrder(bb); bb.clear(); bb.order(ByteOrder.LITTLE_ENDIAN); bb.putShort((short) 300); bb.flip(); showByteOrder(bb); }
From source file:MainClass.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[12]); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); bb.rewind();/*w w w . j a v a 2 s.c o m*/ bb.order(ByteOrder.BIG_ENDIAN); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); bb.rewind(); bb.order(ByteOrder.LITTLE_ENDIAN); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); }
From source file:Endians.java
public static void main(String[] args) { ByteBuffer bb = ByteBuffer.wrap(new byte[12]); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); bb.rewind();//from w ww . j a v a 2 s. co m bb.order(ByteOrder.BIG_ENDIAN); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); bb.rewind(); bb.order(ByteOrder.LITTLE_ENDIAN); bb.asCharBuffer().put("abcdef"); System.out.println(toString(bb.array())); }
From source file:pav.Main.java
/** * @param args//from w ww.ja va2 s. com */ public static void main(String[] args) { System.out.println("------------------------------"); System.out.println("Processing Audio Visualization"); System.out.println("------------------------------\n"); Options options = new Options(); options.addOption("renderer", true, "The Processing render mode to use."); options.addOption("width", true, "The width of the visualization window."); options.addOption("height", true, "The height of the visualization window."); options.addOption("audiosource", true, "Audio source to use (udp or fifo)."); options.addOption("samplesize", true, "Number of samples per frame (512, 1024 or 2048)"); options.addOption("samplerate", true, "The sample rate of the audio data."); options.addOption("byteorder", true, "Byte order of the samples (le or be)"); options.addOption("path", true, "Path to the fifo the fifo audio source should use."); options.addOption("port", true, "Port the udp audio source should listen to."); CommandLineParser parser = new GnuParser(); try { CommandLine cmd = parser.parse(options, args); if (cmd.hasOption("renderer")) { Config.renderer = cmd.getOptionValue("renderer"); } else { Console.out("No render mode specified, using " + Config.renderer + "."); } if (cmd.hasOption("width")) { String option = cmd.getOptionValue("width"); try { Config.windowWidth = Integer.parseInt(option); } catch (NumberFormatException e) { Console.error("Error while parsing command line arguments: width is not a valid integer."); } } else { Console.out("No window width specified, using " + Config.windowWidth + "."); } if (cmd.hasOption("height")) { String option = cmd.getOptionValue("height"); try { Config.windowHeight = Integer.parseInt(option); } catch (NumberFormatException e) { Console.error("Error while parsing command line arguments: height is not a valid integer."); } } else { Console.out("No window height specified, using " + Config.windowHeight + "."); } if (cmd.hasOption("audiosource")) { if (cmd.getOptionValue("audiosource").equals(Config.AUDIO_SOURCE_FIFO)) { Config.audioSource = Config.AUDIO_SOURCE_FIFO; } else if (cmd.getOptionValue("audiosource").equals(Config.AUDIO_SOURCE_UDP)) { Config.audioSource = Config.AUDIO_SOURCE_UDP; } else { Console.error("Invalid audio source specified."); } } else { Console.out("No audio source specified, using " + Config.audioSource + "."); } if (cmd.hasOption("samplesize")) { try { int sampleSize = Integer.parseInt(cmd.getOptionValue("samplesize")); if (sampleSize == 512 || sampleSize == 1024 || sampleSize == 2048) { Config.sampleSize = sampleSize; } else { Console.error("Invalid sample size specified."); } } catch (NumberFormatException e) { Console.error("Error while parsing command line arguments: samplesize is not a valid integer."); } } else { Console.out("No sample size specified, using " + Config.sampleSize + "."); } if (cmd.hasOption("samplerate")) { try { Config.sampleRate = Integer.parseInt(cmd.getOptionValue("samplerate")); } catch (NumberFormatException e) { Console.error("Error while parsing command line arguments: samplerate is not a valid integer."); } } else { Console.out("No sample rate specified, using " + Config.sampleRate + "."); } if (cmd.hasOption("byteorder")) { if (cmd.getOptionValue("byteorder").equals(Config.BYTE_ORDER_LE)) { Config.byteOrder = ByteOrder.LITTLE_ENDIAN; } else if (cmd.getOptionValue("byteorder").equals(Config.BYTE_ORDER_BE)) { Config.byteOrder = ByteOrder.BIG_ENDIAN; } else { Console.error("Invalid byte order specified."); } } else { Console.out("No byte order specified, using " + Config.BYTE_ORDER_LE + "."); } if (Config.audioSource.equals(Config.AUDIO_SOURCE_FIFO)) { if (cmd.hasOption("path")) { if (!(new File(cmd.getOptionValue("path"))).canRead()) { Console.error("Unable to read the specified FIFO, aborting."); return; } Config.fifoPath = cmd.getOptionValue("path"); } else { Console.error("No fifo path specified, aborting."); return; } } if (Config.audioSource.equals(Config.AUDIO_SOURCE_UDP)) { if (cmd.hasOption("port")) { try { Config.udpPort = Integer.parseInt(cmd.getOptionValue("port")); } catch (NumberFormatException e) { Console.error("Error while parsing command line arguments: port is not a valid integer."); } } else { Console.out("No port specified, using " + Config.udpPort + "."); } } } catch (ParseException e) { Console.error("Error while parsing command line arguments: " + e.getMessage()); new HelpFormatter().printHelp("pav", options); } PApplet.main(new String[] { "pav.PAV" }); }
From source file:Main.java
private static byte[] intToByteArray(int data) { return ByteBuffer.allocate(4).order(ByteOrder.LITTLE_ENDIAN).putInt(data).array(); }
From source file:Main.java
public static byte[] my_int_to_bb_le(int myInteger) { return ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putInt(myInteger).array(); }
From source file:Main.java
public static byte[] my_short_to_bb_le(short myShort) { return ByteBuffer.allocate(2).order(ByteOrder.LITTLE_ENDIAN).putShort(myShort).array(); }