List of usage examples for java.lang Byte toString
public static String toString(byte b)
From source file:io.coala.config.AbstractPropertyGetter.java
/** * @param defaultValue//from w w w .j a va 2 s .c o m * @return */ public Byte getByte(final Byte defaultValue) { final String value = get(defaultValue == null ? null : Byte.toString(defaultValue)); return value == null ? null : Byte.valueOf(value); }
From source file:de.micromata.genome.util.strings.converter.StandardStringConverter.java
@Override public Pair<Character, String> objectToString(Object value) { if (value == null) { return Pair.make(ConvertedStringTypes.NULL.getShortType(), null); }/* www . j a v a 2 s .c o m*/ if (value instanceof String) { return Pair.make(ConvertedStringTypes.STRING.getShortType(), (String) value); } if (value instanceof Boolean) { return Pair.make(ConvertedStringTypes.BOOLEAN.getShortType(), Boolean.toString((Boolean) value)); } if (value instanceof Byte) { return Pair.make(ConvertedStringTypes.BYTE.getShortType(), Byte.toString((Byte) value)); } if (value instanceof Short) { return Pair.make(ConvertedStringTypes.SHORT.getShortType(), Short.toString((Short) value)); } if (value instanceof Integer) { return Pair.make(ConvertedStringTypes.INTEGER.getShortType(), Integer.toString((Integer) value)); } if (value instanceof Long) { return Pair.make(ConvertedStringTypes.LONG.getShortType(), Long.toString((Long) value)); } if (value instanceof Float) { return Pair.make(ConvertedStringTypes.FLOAT.getShortType(), Float.toString((Float) value)); } if (value instanceof Double) { return Pair.make(ConvertedStringTypes.DOUBLE.getShortType(), Double.toString((Double) value)); } if (value instanceof Date) { return Pair.make(ConvertedStringTypes.DATE.getShortType(), formatDate((Date) value)); } if (value instanceof BigDecimal) { return Pair.make(ConvertedStringTypes.BIGDECIMAL.getShortType(), formatBigDecimal((BigDecimal) value)); } if (value instanceof Character) { return Pair.make(ConvertedStringTypes.CHAR.getShortType(), Character.toString((Character) value)); } if (value instanceof byte[]) { return Pair.make(ConvertedStringTypes.BYTEARRAY.getShortType(), formatByteArray((byte[]) value)); } if (value instanceof String[]) { return Pair.make(ConvertedStringTypes.STRINGARRAY.getShortType(), formatStringArray((String[]) value)); } if (value instanceof Long[]) { return Pair.make(ConvertedStringTypes.LONGARRAY.getShortType(), formatLongArray((Long[]) value)); } throw new IllegalArgumentException( "StringConverter; Cannot encode object to string: " + value.getClass().getName()); }
From source file:com.rim.logdriver.util.Cat.java
@Override public int run(String[] args) throws Exception { Configuration conf = getConf(); // Configuration processed by ToolRunner // If run by Oozie, then load the Oozie conf too if (System.getProperty("oozie.action.conf.xml") != null) { conf.addResource(new URL("file://" + System.getProperty("oozie.action.conf.xml"))); }//from www.ja v a 2s . co m FileSystem fs = FileSystem.get(conf); // The command line options List<Path> paths = new ArrayList<Path>(); Path outputDir = null; // Load input files from the command line if (args.length < 2) { System.out.println("usage: [genericOptions] input [input ...] output"); System.exit(1); } // Get the files we need from the command line. for (int i = 0; i < args.length - 1; i++) { for (FileStatus f : fs.globStatus(new Path(args[i]))) { paths.add(f.getPath()); } } outputDir = new Path(args[args.length - 1]); Job job = new Job(conf); Configuration jobConf = job.getConfiguration(); job.setJarByClass(Cat.class); jobConf.setIfUnset("mapred.job.name", "Cat Files"); // To propagate credentials within Oozie if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { jobConf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } // Good output separators include things that are unsupported by XML. So we // just send the byte value of the character through. The restriction here // is that it can't be more than 1 byte when UTF-8 encoded, since it will be // read by Pig which only deals with single byte separators. { String outputSeparator = jobConf.get("logdriver.output.field.separator", DEFAULT_OUTPUT_SEPARATOR); byte[] bytes = outputSeparator.getBytes(UTF_8); if (bytes.length != 1) { LOG.error("The output separator must be a single byte in UTF-8."); return 1; } jobConf.set("logdriver.output.field.separator", Byte.toString(bytes[0])); } job.setInputFormatClass(BoomInputFormat.class); job.setMapperClass(CatMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); job.setNumReduceTasks(0); job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); for (Path path : paths) { BoomInputFormat.addInputPath(job, path); } // Run the job. if (conf.getBoolean("job.wait", DEFAULT_WAIT_JOB)) { return job.waitForCompletion(true) ? 0 : 1; } else { job.submit(); return 0; } }
From source file:com.blackberry.logdriver.util.Cat.java
@Override public int run(String[] args) throws Exception { Configuration conf = getConf(); // Configuration processed by ToolRunner // If run by Oozie, then load the Oozie conf too if (System.getProperty("oozie.action.conf.xml") != null) { conf.addResource(new URL("file://" + System.getProperty("oozie.action.conf.xml"))); }// w w w. j a v a2 s . c o m FileSystem fs = FileSystem.get(conf); // The command line options List<Path> paths = new ArrayList<Path>(); Path outputDir = null; // Load input files from the command line if (args.length < 2) { System.out.println("usage: [genericOptions] input [input ...] output"); System.exit(1); } // Get the files we need from the command line. for (int i = 0; i < args.length - 1; i++) { for (FileStatus f : fs.globStatus(new Path(args[i]))) { paths.add(f.getPath()); } } outputDir = new Path(args[args.length - 1]); @SuppressWarnings("deprecation") Job job = new Job(conf); Configuration jobConf = job.getConfiguration(); job.setJarByClass(Cat.class); jobConf.setIfUnset("mapred.job.name", "Cat Files"); // To propagate credentials within Oozie if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { jobConf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } // Good output separators include things that are unsupported by XML. So we // just send the byte value of the character through. The restriction here // is that it can't be more than 1 byte when UTF-8 encoded, since it will be // read by Pig which only deals with single byte separators. { String outputSeparator = jobConf.get("logdriver.output.field.separator", DEFAULT_OUTPUT_SEPARATOR); byte[] bytes = outputSeparator.getBytes(UTF_8); if (bytes.length != 1) { LOG.error("The output separator must be a single byte in UTF-8."); return 1; } jobConf.set("logdriver.output.field.separator", Byte.toString(bytes[0])); } job.setInputFormatClass(BoomInputFormat.class); job.setMapperClass(CatMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); job.setNumReduceTasks(0); job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); for (Path path : paths) { BoomInputFormat.addInputPath(job, path); } // Run the job. if (conf.getBoolean("job.wait", DEFAULT_WAIT_JOB)) { return job.waitForCompletion(true) ? 0 : 1; } else { job.submit(); return 0; } }
From source file:org.apache.hadoop.hbase.replication.ReplicationZookeeperWrapper.java
/** * Constructor used by region servers, connects to the peer cluster right away. * * @param zookeeperWrapper zkw to wrap/* w w w.j a va 2s. c o m*/ * @param conf conf to use * @param replicating atomic boolean to start/stop replication * @param rsName the name of this region server, null if * using RZH only to use the helping methods * @throws IOException */ public ReplicationZookeeperWrapper(ZooKeeperWrapper zookeeperWrapper, Configuration conf, final AtomicBoolean replicating, String rsName) throws IOException { this.zookeeperWrapper = zookeeperWrapper; this.conf = conf; String replicationZNodeName = conf.get("zookeeper.znode.replication", "replication"); String peersZNodeName = conf.get("zookeeper.znode.replication.peers", "peers"); String repMasterZNodeName = conf.get("zookeeper.znode.replication.master", "master"); this.replicationStateNodeName = conf.get("zookeeper.znode.replication.state", "state"); String clusterIdZNodeName = conf.get("zookeeper.znode.replication.clusterId", "clusterId"); String rsZNodeName = conf.get("zookeeper.znode.replication.rs", "rs"); String thisCluster = this.conf.get(HConstants.ZOOKEEPER_QUORUM) + ":" + this.conf.get(HConstants.ZOOKEEPER_CLIENT_PORT) + ":" + this.conf.get(HConstants.ZOOKEEPER_ZNODE_PARENT); this.peerClusters = new HashMap<String, ZooKeeperWrapper>(); this.replicationZNode = zookeeperWrapper.getZNode(zookeeperWrapper.getParentZNode(), replicationZNodeName); this.peersZNode = zookeeperWrapper.getZNode(replicationZNode, peersZNodeName); this.rsZNode = zookeeperWrapper.getZNode(replicationZNode, rsZNodeName); this.replicating = replicating; setReplicating(); String idResult = Bytes.toString(this.zookeeperWrapper.getData(this.replicationZNode, clusterIdZNodeName)); this.clusterId = idResult == null ? Byte.toString(HConstants.DEFAULT_CLUSTER_ID) : idResult; String address = Bytes.toString(this.zookeeperWrapper.getData(this.replicationZNode, repMasterZNodeName)); this.replicationMaster = thisCluster.equals(address); LOG.info("This cluster (" + thisCluster + ") is a " + (this.replicationMaster ? "master" : "slave") + " for replication" + ", compared with (" + address + ")"); if (rsName != null) { this.rsServerNameZnode = this.zookeeperWrapper.getZNode(rsZNode, rsName); List<String> znodes = this.zookeeperWrapper.listZnodes(this.peersZNode, new ReplicationStatusWatcher()); if (znodes != null) { for (String znode : znodes) { connectToPeer(znode); } } } else { this.rsServerNameZnode = null; } }
From source file:org.jts.eclipse.conversion.cjsidl.ConversionUtil.java
/** * Used to fill a gap where a maximum value isn't specified in a range. * @param val - the current value, if there is one. * @param inputType - the input data type that the maximum should fit within * //from ww w . ja v a2 s. c o m * @return - the original value if it exists, or the maximum value allowed within * the inputType specified. */ public static String getCountMax(String val, String inputType) { String result = val; if (result == null || result.isEmpty()) { if (inputType.equals("byte") || inputType.equals("int8")) { result = Byte.toString(Byte.MAX_VALUE); } else if (inputType.equals("short integer") || inputType.equals("int16")) { result = Short.toString(Short.MAX_VALUE); } else if (inputType.equals("integer") || inputType.equals("int32")) { result = Integer.toString(Integer.MAX_VALUE); } else if (inputType.equals("long integer") || inputType.equals("int64")) { result = Long.toString(Long.MAX_VALUE); } else if (inputType.equals("unsigned byte") || inputType.equals("uint8")) { result = Short.toString((short) (Byte.MAX_VALUE * 2 + 1)); } else if (inputType.equals("unsigned short integer") || inputType.equals("uint16")) { result = Integer.toString((int) (Short.MAX_VALUE * 2 + 1)); } else if (inputType.equals("unsigned integer") || inputType.equals("uint32")) { result = Long.toString((long) (Integer.MAX_VALUE * 2 + 1)); } else if (inputType.equals("unsigned long integer") || inputType.equals("uint64")) { result = "18446744073709551615"; } else if (inputType.equals("float") || inputType.equals("float")) { result = Float.toString(Float.MAX_VALUE); } else if (inputType.equals("long float") || inputType.equals("double")) { result = Double.toString(Double.MAX_VALUE); } } return result; }
From source file:com.rim.logdriver.util.Search.java
@Override public int run(String[] args) throws Exception { Configuration conf = getConf(); // Configuration processed by ToolRunner // If run by Oozie, then load the Oozie conf too if (System.getProperty("oozie.action.conf.xml") != null) { conf.addResource(new URL("file://" + System.getProperty("oozie.action.conf.xml"))); }/*from ww w .j a v a 2 s. c om*/ FileSystem fs = FileSystem.get(conf); // The command line options String searchString = null; List<Path> paths = new ArrayList<Path>(); Path outputDir = null; // Load input files from the command line if (args.length < 3) { System.out.println("usage: [genericOptions] searchString input [input ...] output"); System.exit(1); } // Get the files we need from the command line. searchString = args[0]; for (int i = 1; i < args.length - 1; i++) { for (FileStatus f : fs.globStatus(new Path(args[i]))) { paths.add(f.getPath()); } } outputDir = new Path(args[args.length - 1]); Job job = new Job(conf); Configuration jobConf = job.getConfiguration(); job.setJarByClass(Search.class); jobConf.setIfUnset("mapred.job.name", "Search Files"); // To propagate credentials within Oozie if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { jobConf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } // Good output separators include things that are unsupported by XML. So we // just send the byte value of the character through. The restriction here // is that it can't be more than 1 byte when UTF-8 encoded, since it will be // read by Pig which only deals with single byte separators. { String outputSeparator = jobConf.get("logdriver.output.field.separator", DEFAULT_OUTPUT_SEPARATOR); byte[] bytes = outputSeparator.getBytes(UTF_8); if (bytes.length != 1) { LOG.error("The output separator must be a single byte in UTF-8."); return 1; } jobConf.set("logdriver.output.field.separator", Byte.toString(bytes[0])); } jobConf.set("logdriver.search.string", searchString); job.setInputFormatClass(BoomInputFormat.class); job.setMapperClass(SearchMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); job.setNumReduceTasks(0); // And set the output as usual job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); for (Path path : paths) { BoomInputFormat.addInputPath(job, path); } // Run the job. if (conf.getBoolean("job.wait", DEFAULT_WAIT_JOB)) { return job.waitForCompletion(true) ? 0 : 1; } else { job.submit(); return 0; } }
From source file:com.blackberry.logdriver.util.Search.java
@Override public int run(String[] args) throws Exception { Configuration conf = getConf(); // Configuration processed by ToolRunner // If run by Oozie, then load the Oozie conf too if (System.getProperty("oozie.action.conf.xml") != null) { conf.addResource(new URL("file://" + System.getProperty("oozie.action.conf.xml"))); }// w w w . j av a 2s. c om FileSystem fs = FileSystem.get(conf); // The command line options String searchString = null; List<Path> paths = new ArrayList<Path>(); Path outputDir = null; // Load input files from the command line if (args.length < 3) { System.out.println("usage: [genericOptions] searchString input [input ...] output"); System.exit(1); } // Get the files we need from the command line. searchString = args[0]; for (int i = 1; i < args.length - 1; i++) { for (FileStatus f : fs.globStatus(new Path(args[i]))) { paths.add(f.getPath()); } } outputDir = new Path(args[args.length - 1]); @SuppressWarnings("deprecation") Job job = new Job(conf); Configuration jobConf = job.getConfiguration(); job.setJarByClass(Search.class); jobConf.setIfUnset("mapred.job.name", "Search Files"); // To propagate credentials within Oozie if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { jobConf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } // Good output separators include things that are unsupported by XML. So we // just send the byte value of the character through. The restriction here // is that it can't be more than 1 byte when UTF-8 encoded, since it will be // read by Pig which only deals with single byte separators. { String outputSeparator = jobConf.get("logdriver.output.field.separator", DEFAULT_OUTPUT_SEPARATOR); byte[] bytes = outputSeparator.getBytes(UTF_8); if (bytes.length != 1) { LOG.error("The output separator must be a single byte in UTF-8."); return 1; } jobConf.set("logdriver.output.field.separator", Byte.toString(bytes[0])); } jobConf.set("logdriver.search.string", searchString); job.setInputFormatClass(BoomInputFormat.class); job.setMapperClass(SearchMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); job.setNumReduceTasks(0); // And set the output as usual job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); for (Path path : paths) { BoomInputFormat.addInputPath(job, path); } // Run the job. if (conf.getBoolean("job.wait", DEFAULT_WAIT_JOB)) { return job.waitForCompletion(true) ? 0 : 1; } else { job.submit(); return 0; } }
From source file:SignificantFigures.java
/** * Create a SignificantFigures object from a byte. * * @param number an 8 bit integer./*w w w .jav a 2s . c o m*/ * * @since ostermillerutils 1.00.00 */ public SignificantFigures(byte number) { original = Byte.toString(number); try { parse(original); } catch (NumberFormatException nfe) { digits = null; } }
From source file:com.rim.logdriver.util.Grep.java
@Override public int run(String[] args) throws Exception { Configuration conf = getConf(); // Configuration processed by ToolRunner // If run by Oozie, then load the Oozie conf too if (System.getProperty("oozie.action.conf.xml") != null) { conf.addResource(new URL("file://" + System.getProperty("oozie.action.conf.xml"))); }/*from ww w.j a v a2 s. c om*/ FileSystem fs = FileSystem.get(conf); // The command line options String regex = null; List<Path> paths = new ArrayList<Path>(); Path outputDir = null; // Load input files from the command line if (args.length < 3) { System.out.println("usage: [genericOptions] regex input [input ...] output"); System.exit(1); } // Get the files we need from the command line. regex = args[0]; for (int i = 1; i < args.length - 1; i++) { for (FileStatus f : fs.globStatus(new Path(args[i]))) { paths.add(f.getPath()); } } outputDir = new Path(args[args.length - 1]); Job job = new Job(conf); Configuration jobConf = job.getConfiguration(); job.setJarByClass(Grep.class); jobConf.setIfUnset("mapred.job.name", "Grep Files"); // To propagate credentials within Oozie if (System.getenv("HADOOP_TOKEN_FILE_LOCATION") != null) { jobConf.set("mapreduce.job.credentials.binary", System.getenv("HADOOP_TOKEN_FILE_LOCATION")); } // Good output separators include things that are unsupported by XML. So we // just send the byte value of the character through. The restriction here // is that it can't be more than 1 byte when UTF-8 encoded, since it will be // read by Pig which only deals with single byte separators. { String outputSeparator = jobConf.get("logdriver.output.field.separator", DEFAULT_OUTPUT_SEPARATOR); byte[] bytes = outputSeparator.getBytes(UTF_8); if (bytes.length != 1) { LOG.error("The output separator must be a single byte in UTF-8."); return 1; } jobConf.set("logdriver.output.field.separator", Byte.toString(bytes[0])); } jobConf.set("logdriver.grep.regex", Base64.encodeBase64String(regex.getBytes("UTF-8"))); job.setInputFormatClass(BoomInputFormat.class); job.setMapperClass(GrepMapper.class); job.setMapOutputKeyClass(Text.class); job.setMapOutputValueClass(NullWritable.class); job.setNumReduceTasks(0); // And set the output as usual job.setOutputFormatClass(TextOutputFormat.class); TextOutputFormat.setOutputPath(job, outputDir); for (Path path : paths) { BoomInputFormat.addInputPath(job, path); } // Run the job. if (conf.getBoolean("job.wait", DEFAULT_WAIT_JOB)) { return job.waitForCompletion(true) ? 0 : 1; } else { job.submit(); return 0; } }