List of usage examples for java.lang Byte MIN_VALUE
byte MIN_VALUE
To view the source code for java.lang Byte MIN_VALUE.
Click Source Link
From source file:org.sakaiproject.content.impl.serialize.impl.test.ByteStorageConversionCheck.java
@Test public void testMaxMinConversion() { byte[] bin = new byte[2]; char[] cin = new char[2]; byte[] bout = new byte[2]; bin[0] = Byte.MIN_VALUE; bin[1] = Byte.MAX_VALUE;//from ww w . ja v a 2 s .c o m ByteStorageConversion.toChar(bin, 0, cin, 0, bin.length); ByteStorageConversion.toByte(cin, 0, bout, 0, cin.length); log.info(" Min Byte " + bin[0] + ": Stored as int[" + (int) cin[0] + "] char[" + cin[0] + "]\n"); log.info(" Max Byte " + bin[1] + ": Stored as int[" + (int) cin[1] + "] char[" + cin[1] + "]\n"); for (int i = 0; i < bin.length; i++) { if (bin[i] != bout[i]) { log.warn("Internal Byte conversion failed at " + bin[i] + "=>" + (int) cin[i] + "=>" + bout[i]); } } }
From source file:it.scoppelletti.security.keygen.DESKeyToPropertySetProvider.java
public Properties toProperties(Key key) { byte[] data;//www . j a va 2s . c om SecretKey desKey; SecretKeyFactory keyFactory; DESKeySpec param; Properties props; if (!(key instanceof SecretKey)) { return null; } try { keyFactory = SecretKeyFactory.getInstance(DESKeyFactory.ALGORITHM); } catch (NoSuchAlgorithmException ex) { return null; } try { desKey = keyFactory.translateKey((SecretKey) key); } catch (InvalidKeyException ex) { return null; } try { param = (DESKeySpec) keyFactory.getKeySpec(desKey, DESKeySpec.class); } catch (InvalidKeySpecException ex) { return null; } props = new Properties(); props.setProperty(CryptoUtils.PROP_KEYFACTORY, DESKeyFactory.class.getName()); data = param.getKey(); props.setProperty(DESKeyFactory.PROP_KEY, Hex.encodeHexString(data)); Arrays.fill(data, Byte.MIN_VALUE); return props; }
From source file:it.scoppelletti.security.keygen.DESedeKeyToPropertySetProvider.java
public Properties toProperties(Key key) { byte[] data;//w w w . j a v a2 s. co m SecretKey desKey; SecretKeyFactory keyFactory; DESedeKeySpec param; Properties props; if (!(key instanceof SecretKey)) { return null; } try { keyFactory = SecretKeyFactory.getInstance(DESedeKeyFactory.ALGORITHM); } catch (NoSuchAlgorithmException ex) { return null; } try { desKey = keyFactory.translateKey((SecretKey) key); } catch (InvalidKeyException ex) { return null; } try { param = (DESedeKeySpec) keyFactory.getKeySpec(desKey, DESedeKeySpec.class); } catch (InvalidKeySpecException ex) { return null; } props = new Properties(); props.setProperty(CryptoUtils.PROP_KEYFACTORY, DESedeKeyFactory.class.getName()); data = param.getKey(); props.setProperty(DESedeKeyFactory.PROP_KEY, Hex.encodeHexString(data)); Arrays.fill(data, Byte.MIN_VALUE); return props; }
From source file:org.tranche.server.logs.LogUtil.java
/** * Retrieve IP address as a formatted string. * @param IPBytes// ww w. jav a 2s .co m * @return * @throws java.lang.Exception */ public static String getIPString(byte[] IPBytes) throws Exception { StringBuffer ip = new StringBuffer(); if (IPBytes.length == 4) { for (int i = 0; i < IPBytes.length; i++) { // Convert to unsigned int int next = IPBytes[i] + Math.abs(Byte.MIN_VALUE); ip.append(next); if (i < IPBytes.length - 1) { ip.append("."); } } } else if (IPBytes.length == 16) { throw new UnsupportedOperationException("Implement IPv6."); } else { throw new Exception("Unrecognized IP version for " + IPBytes.length + ". Expecting 4 bytes (IPv4) or 16 bytes (IPv6)."); } return ip.toString(); }
From source file:org.voltdb.ClientResponseImpl.java
/** * Another constructor for test and error responses * @param client_handle//from w w w. j a va2s. com * @param status * @param results * @param extra */ public ClientResponseImpl(long txn_id, long client_handle, int basePartition, Status status, VoltTable[] results, String statusString) { this(txn_id, client_handle, basePartition, status, Byte.MIN_VALUE, null, results, statusString, null); }
From source file:gedi.util.MathUtils.java
/** * Throws an exception if n is either a real or to big to be represented by a byte. * @param n/*from ww w . ja v a2 s .com*/ * @return */ public static byte byteValueExact(Number n) { if (n instanceof Byte) return n.byteValue(); double d = n.doubleValue(); long l = n.longValue(); if (d == (double) l) { if (l >= Byte.MIN_VALUE && l <= Byte.MAX_VALUE) return (byte) l; } throw new NumberFormatException(); }
From source file:org.omnaest.utils.codec.EncoderAndDecoderAlphanumericTokens.java
@Override public String encode(String source) { ///*from w w w. j a v a 2 s . c o m*/ final StringBuffer stringBuffer = new StringBuffer(); // if (source != null) { // final Pattern pattern = Pattern.compile(ALPHA_LETTER_REGEX); final int length = source.length(); for (int ii = 0; ii < length; ii++) { final String token = source.substring(ii, ii + 1); final Matcher matcher = pattern.matcher(String.valueOf(token)); if (matcher.matches()) { stringBuffer.append(token); } else { try { // final byte[] bytes = token.getBytes(CHARSET_UTF_8); for (byte byteToken : bytes) { stringBuffer.append(String.format("%0" + INTERVAL + "d", byteToken - Byte.MIN_VALUE)); } } catch (Exception e) { Assert.fails(e); } } } } // return stringBuffer.toString(); }
From source file:org.godhuli.rhipe.hbase.Util.java
public static Scan[] generateBytePrefixScans(Calendar startCal, Calendar endCal, String dateFormat, ArrayList<Pair<String, String>> columns, int caching, boolean cacheBlocks) { ArrayList<Scan> scans = new ArrayList<Scan>(); SimpleDateFormat rowsdf = new SimpleDateFormat(dateFormat); long endTime = getEndTimeAtResolution(endCal.getTimeInMillis(), Calendar.DATE); byte[] temp = new byte[1]; while (startCal.getTimeInMillis() < endTime) { for (byte b = Byte.MIN_VALUE; b < Byte.MAX_VALUE; b++) { int d = Integer.parseInt(rowsdf.format(startCal.getTime())); Scan s = new Scan(); s.setCaching(caching);// w ww .j ava 2 s.co m s.setCacheBlocks(cacheBlocks); // add columns for (Pair<String, String> pair : columns) { s.addColumn(pair.getFirst().getBytes(), pair.getSecond().getBytes()); } temp[0] = b; s.setStartRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d)))); s.setStopRow(Bytes.add(temp, Bytes.toBytes(String.format("%06d", d + 1)))); if (LOG.isDebugEnabled()) { LOG.info("Adding start-stop range: " + temp + String.format("%06d", d) + " - " + temp + String.format("%06d", d + 1)); } scans.add(s); } startCal.add(Calendar.DATE, 1); } return scans.toArray(new Scan[scans.size()]); }
From source file:org.voltdb.ClientResponseImpl.java
/** * And another....//w w w .j a v a2 s .com * @param status * @param results * @param extra * @param e */ public ClientResponseImpl(long txn_id, long client_handle, int basePartition, Status status, VoltTable[] results, String statusString, SerializableException e) { this(txn_id, client_handle, basePartition, status, Byte.MIN_VALUE, null, results, statusString, e); }
From source file:org.apache.hadoop.hive.accumulo.AccumuloTestSetup.java
protected void createAccumuloTable(Connector conn) throws TableExistsException, TableNotFoundException, AccumuloException, AccumuloSecurityException { TableOperations tops = conn.tableOperations(); if (tops.exists(TABLE_NAME)) { tops.delete(TABLE_NAME);/* ww w.j a v a 2 s . c o m*/ } tops.create(TABLE_NAME); boolean[] booleans = new boolean[] { true, false, true }; byte[] bytes = new byte[] { Byte.MIN_VALUE, -1, Byte.MAX_VALUE }; short[] shorts = new short[] { Short.MIN_VALUE, -1, Short.MAX_VALUE }; int[] ints = new int[] { Integer.MIN_VALUE, -1, Integer.MAX_VALUE }; long[] longs = new long[] { Long.MIN_VALUE, -1, Long.MAX_VALUE }; String[] strings = new String[] { "Hadoop, Accumulo", "Hive", "Test Strings" }; float[] floats = new float[] { Float.MIN_VALUE, -1.0F, Float.MAX_VALUE }; double[] doubles = new double[] { Double.MIN_VALUE, -1.0, Double.MAX_VALUE }; HiveDecimal[] decimals = new HiveDecimal[] { HiveDecimal.create("3.14159"), HiveDecimal.create("2.71828"), HiveDecimal.create("0.57721") }; Date[] dates = new Date[] { Date.valueOf("2014-01-01"), Date.valueOf("2014-03-01"), Date.valueOf("2014-05-01") }; Timestamp[] timestamps = new Timestamp[] { new Timestamp(50), new Timestamp(100), new Timestamp(150) }; BatchWriter bw = conn.createBatchWriter(TABLE_NAME, new BatchWriterConfig()); final String cf = "cf"; try { for (int i = 0; i < 3; i++) { Mutation m = new Mutation("key-" + i); m.put(cf, "cq-boolean", Boolean.toString(booleans[i])); m.put(cf.getBytes(), "cq-byte".getBytes(), new byte[] { bytes[i] }); m.put(cf, "cq-short", Short.toString(shorts[i])); m.put(cf, "cq-int", Integer.toString(ints[i])); m.put(cf, "cq-long", Long.toString(longs[i])); m.put(cf, "cq-string", strings[i]); m.put(cf, "cq-float", Float.toString(floats[i])); m.put(cf, "cq-double", Double.toString(doubles[i])); m.put(cf, "cq-decimal", decimals[i].toString()); m.put(cf, "cq-date", dates[i].toString()); m.put(cf, "cq-timestamp", timestamps[i].toString()); bw.addMutation(m); } } finally { bw.close(); } }