List of usage examples for java.lang Integer reverseBytes
@HotSpotIntrinsicCandidate public static int reverseBytes(int i)
From source file:MainClass.java
public static void main(String args[]) { System.out.println(Integer.reverseBytes(10)); System.out.println(Integer.reverseBytes(-10)); System.out.println(Integer.reverseBytes(0)); }
From source file:Main.java
public static void main(String args[]) { int n = 170; // 10101010 System.out.println(Integer.reverseBytes(n)); }
From source file:Main.java
public static int readInt(DataInputStream is) throws IOException { return Integer.reverseBytes(is.readInt()); }
From source file:Main.java
public static void writeInt(DataOutputStream os, int i) throws IOException { os.writeInt(Integer.reverseBytes(i)); }
From source file:org.namelessrom.devicecontrol.net.NetworkInfo.java
public static String getWifiIp() { final WifiManager wifiManager = (WifiManager) Application.get().getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }//from w w w .j a v a 2 s .c o m final byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString; try { ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress(); } catch (UnknownHostException ex) { ipAddressString = "0.0.0.0"; } return ipAddressString; }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Converts a byte array to an int value considering it was written in big-endian format. * @param bytes byte array/*from w ww. j a va 2 s. c o m*/ * @param offset offset into array * @return the int value */ public static int toInt(byte[] bytes, int offset) { if (littleEndian) { return Integer.reverseBytes(theUnsafe.getInt(bytes, offset + BYTE_ARRAY_BASE_OFFSET)); } else { return theUnsafe.getInt(bytes, offset + BYTE_ARRAY_BASE_OFFSET); } }
From source file:github.daneren2005.serverproxy.ServerProxy.java
public String getPublicAddress(String request) { WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); int ipAddress = wifiManager.getConnectionInfo().getIpAddress(); if (ByteOrder.nativeOrder().equals(ByteOrder.LITTLE_ENDIAN)) { ipAddress = Integer.reverseBytes(ipAddress); }//from w ww . j a v a2 s . c o m byte[] ipByteArray = BigInteger.valueOf(ipAddress).toByteArray(); String ipAddressString = null; try { ipAddressString = InetAddress.getByAddress(ipByteArray).getHostAddress(); } catch (UnknownHostException ex) { Log.e(TAG, "Unable to get host address."); } return getAddress(ipAddressString, request); }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Put an int value out to the specified byte array position in big-endian format. * @param bytes the byte array/* w ww . j a v a2s .c om*/ * @param offset position in the array * @param val int to write out * @return incremented offset */ public static int putInt(byte[] bytes, int offset, int val) { if (littleEndian) { val = Integer.reverseBytes(val); } theUnsafe.putInt(bytes, offset + BYTE_ARRAY_BASE_OFFSET, val); return offset + Bytes.SIZEOF_INT; }
From source file:org.squidy.nodes.laserpointer.proxy.ProxyCam.java
public void run() { updateConfig();//ww w. j a v a 2s . c o m while (running) { int bytesRead = 0; LOG.debug("wait for image"); try { if (debug) { debugWriter.newLine(); debugWriter.write("========= New image ========="); debugWriter.newLine(); } BufferedInputStream bis = new BufferedInputStream(input); // read 4-byte header with number of bytes and allocate byte[] DataInputStream dis = new DataInputStream(bis); int size = Integer.reverseBytes(dis.readInt()); //System.out.println(Integer.toHexString(size)); //System.out.println(size); byte[] sizebytes = new byte[4]; sizebytes[0] = (byte) (size >> 24); sizebytes[1] = (byte) (size >> 16); sizebytes[2] = (byte) (size >> 8); sizebytes[3] = (byte) size; ProxyConfig.getConfigConnection().sendMessage(sizebytes); bytes = new byte[size]; bytesRead = 0; do { bytes[bytesRead] = (byte) bis.read(); bytesRead++; } while (bytesRead < size); LOG.debug("Total bytes read: " + bytesRead + "."); if (debug) { debugWriter.newLine(); debugWriter.write("========= " + aoiW + "x" + aoiH + " ========="); debugWriter.newLine(); debugWriter.flush(); } } catch (IOException e) { LOG.error("Connection error occured."); close(); return; } try { ProxyConfig.getConfigConnection().sendMessage(bytes); } catch (IOException e) { LOG.error("Couldn't send image to config."); } } close(); }
From source file:org.apache.hadoop.hbase.util.UnsafeAccess.java
/** * Reads an int value at the given buffer's offset considering it was written in big-endian * format.//w ww .j a v a 2 s.c o m * * @param buf * @param offset * @return int value at offset */ public static int toInt(ByteBuffer buf, int offset) { if (littleEndian) { return Integer.reverseBytes(getAsInt(buf, offset)); } return getAsInt(buf, offset); }