List of usage examples for java.lang Byte toString
public static String toString(byte b)
From source file:byps.BBufferJson.java
public void putByte(byte v) { putJsonValueAscii(null, Byte.toString(v), STRING_WITHOUT_QUOTE); }
From source file:de.unistuttgart.ipvs.pmp.infoapp.webservice.properties.BatteryProperties.java
@Override public void commit() throws InternalDatabaseException, InvalidParameterException, IOException { try {// ww w. j av a2s . c om List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); params.add(new BasicNameValuePair("technology", this.technology)); params.add(new BasicNameValuePair("health", Byte.toString(this.health))); super.service.requestPostService("update_battery.php", params); } catch (JSONException e) { throw new IOException("Server returned no valid JSON object: " + e); } }
From source file:org.catechis.Transformer.java
/** *Takes a string of encoded text and return its bytes in a string to avoid *the new string from being encoded./*from ww w . j a v a 2 s.c om*/ */ public static String getByteString(String text) { byte[] text_bytes = text.getBytes(); // prepare the text int b_size = text_bytes.length; int i = 0; StringBuffer str_buf = new StringBuffer(); while (i < b_size) { //str_buf.append("-"); str_buf.append(Byte.toString(text_bytes[i])); i++; } String str_bytes = new String(str_buf); return str_bytes; }
From source file:org.duracloud.common.util.EncryptionUtil.java
/** * Encodes a byte array as a String without using a charset * to ensure that the exact bytes can be retrieved on decode. *///from ww w. j a va2 s. c om private String encodeBytes(byte[] cipherText) { StringBuffer cipherStringBuffer = new StringBuffer(); for (int i = 0; i < cipherText.length; i++) { byte b = cipherText[i]; cipherStringBuffer.append(Byte.toString(b) + ":"); } return cipherStringBuffer.toString(); }
From source file:org.catechis.Transformer.java
/** * Takes a string of encoded text and return its bytes in a string to avoid *the new string from being encoded./*ww w. jav a2 s . c om*/ */ public static String getByteStringWithEncoding(String text, String charsetName) { byte[] text_bytes = text.getBytes(); // prepare the text int b_size = text_bytes.length; int i = 0; StringBuffer str_buf = new StringBuffer(); while (i < b_size) { //str_buf.append("-"); str_buf.append(Byte.toString(text_bytes[i])); i++; } String str_bytes = new String(text_bytes); return str_bytes; }
From source file:byps.BBufferJson.java
public void putByte(String name, byte v) { putJsonValueAscii(name, Byte.toString(v), STRING_WITHOUT_QUOTE); }
From source file:pt.ist.vaadinframework.ui.DefaultFieldFactory.java
/** * @see pt.ist.vaadinframework.ui.AbstractFieldFactory#makeField(com.vaadin.data.Item, java.lang.Object, * com.vaadin.ui.Component)/*from w ww. ja va2 s. c o m*/ */ @Override protected Field makeField(Item item, Object propertyId, Component uiContext) { Class<?> type = item.getItemProperty(propertyId).getType(); if (String.class.isAssignableFrom(type)) { TextField field = new TextField(); field.setNullSettingAllowed(true); field.setNullRepresentation(StringUtils.EMPTY); return field; } if (Collection.class.isAssignableFrom(type) && item.getItemProperty(propertyId) instanceof AbstractBufferedContainer) { return new ContainerEditor<Object>(this, bundlename, ((AbstractBufferedContainer<?, ?, ?>) item.getItemProperty(propertyId)).getElementType()); } if (AbstractDomainObject.class.isAssignableFrom(type)) { Select select = new Select(); select.setWidth(100, Sizeable.UNITS_PERCENTAGE); select.setImmediate(true); return select; } if (Collection.class.isAssignableFrom(type)) { OptionGroup group = new OptionGroup(); group.setMultiSelect(true); group.setWidth(100, Sizeable.UNITS_PERCENTAGE); group.setImmediate(true); return group; } if (Byte.class.isAssignableFrom(type)) { return new PrimitiveField(new ByteValidator(), Byte.toString(Byte.MAX_VALUE).length() + 1); } if (Short.class.isAssignableFrom(type)) { return new PrimitiveField(new ShortValidator(), Short.toString(Short.MAX_VALUE).length() + 1); } if (Integer.class.isAssignableFrom(type)) { return new PrimitiveField(new IntegerValidator(), Integer.toString(Integer.MAX_VALUE).length() + 1); } if (Long.class.isAssignableFrom(type)) { return new PrimitiveField(new LongValidator(), Long.toString(Long.MAX_VALUE).length() + 1); } if (Float.class.isAssignableFrom(type)) { return new PrimitiveField(new FloatValidator(), Float.toString(Float.MAX_VALUE).length() + 1); } if (Double.class.isAssignableFrom(type)) { return new PrimitiveField(new DoubleValidator(), Double.toString(Double.MAX_VALUE).length() + 1); } if (Boolean.class.isAssignableFrom(type)) { return new CheckBox(); } if (Character.class.isAssignableFrom(type)) { return new PrimitiveField(new CharacterValidator(), 1); } if (BigDecimal.class.isAssignableFrom(type)) { return new PrimitiveField(new BigDecimalValidator(), -1); } if (Enum.class.isAssignableFrom(type)) { return new EnumField((Class<? extends Enum<?>>) item.getItemProperty(propertyId).getType()); } if (Date.class.isAssignableFrom(type)) { DateField field = new DateField(); field.setResolution(DateField.RESOLUTION_DAY); return field; } if (Item.class.isAssignableFrom(type)) { Form form = new Form() { @Override public void setPropertyDataSource(Property newDataSource) { setItemDataSource((Item) newDataSource); }; }; form.setImmediate(true); form.setFormFieldFactory(this); return form; } if (MultiLanguageString.class.isAssignableFrom(type)) { return new MultiLanguageStringField(bundlename, Language.pt, Language.en); } if (DateTime.class.isAssignableFrom(type)) { PopupDateTimeField field = new PopupDateTimeField(); field.setResolution(DateField.RESOLUTION_SEC); return field; } if (LocalDate.class.isAssignableFrom(type)) { PopupLocalDateField field = new PopupLocalDateField(); field.setResolution(DateField.RESOLUTION_DAY); return field; } if (URL.class.isAssignableFrom(type)) { TextField field = new TextField(); field.setNullSettingAllowed(true); field.setNullRepresentation(StringUtils.EMPTY); field.addValidator(new URLValidator()); return field; } Select select = new Select(); select.setWidth(100, Sizeable.UNITS_PERCENTAGE); select.setImmediate(true); return select; }
From source file:org.apache.axis2.databinding.utils.ConverterUtil.java
public static String convertToString(byte i) { return Byte.toString(i); }
From source file:org.commoncrawl.service.queryserver.master.S3Helper.java
static int scanForGZIPHeader(ByteBuffer byteBuffer) throws IOException { LOG.info("*** SCANNING FOR GZIP MAGIC Bytes:" + Byte.toString((byte) StreamingArcFileReader.GZIP_MAGIC) + " " + Byte.toString((byte) (StreamingArcFileReader.GZIP_MAGIC >> 8)) + " BufferSize is:" + byteBuffer.limit() + " Remaining:" + byteBuffer.remaining()); int limit = byteBuffer.limit(); while (byteBuffer.position() + 2 < limit) { //LOG.info("Reading Byte At:"+ byteBuffer.position()); int b = byteBuffer.get(); //LOG.info("First Byte is:"+ b); if (b == (byte) (StreamingArcFileReader.GZIP_MAGIC)) { byteBuffer.mark();//from www . j a v a 2 s .c om byte b2 = byteBuffer.get(); //LOG.info("Second Byte is:"+ b2); if (b2 == (byte) (StreamingArcFileReader.GZIP_MAGIC >> 8)) { byte b3 = byteBuffer.get(); if (b3 == Deflater.DEFLATED) { LOG.info("Found GZip Magic at:" + (byteBuffer.position() - 3)); return byteBuffer.position() - 3; } } byteBuffer.reset(); } } LOG.error("Failed to Find GZIP Magic!!"); //LOG.error(Arrays.toString(byteBuffer.array())); return -1; }
From source file:com.marklogic.contentpump.SingleDocumentWriter.java
@Override public void write(DocumentURI uri, MarkLogicDocument content) throws IOException, InterruptedException { OutputStream os = null;/*from www .ja v a 2 s . c o m*/ try { String childPath = URIUtil.getPathFromURI(uri); Path path; if (childPath.charAt(0) == '/') { // concatenate outputPath with path to form the path path = new Path(dir.toString() + childPath); } else { path = new Path(dir, childPath); } FileSystem fs = path.getFileSystem(conf); if (fs instanceof DistributedFileSystem) { os = fs.create(path, false); } else { File f = new File(path.toUri().getPath()); if (!f.exists()) { f.getParentFile().mkdirs(); f.createNewFile(); } os = new FileOutputStream(f, false); } ContentType type = content.getContentType(); if (ContentType.BINARY.equals(type)) { if (content.isStreamable()) { InputStream is = null; try { is = content.getContentAsByteStream(); long size = content.getContentSize(); long bufSize = Math.min(size, 512 << 10); byte[] buf = new byte[(int) bufSize]; for (long toRead = size, read = 0; toRead > 0; toRead -= read) { read = is.read(buf, 0, (int) bufSize); if (read > 0) { os.write(buf, 0, (int) read); } else { LOG.error("Premature EOF: uri=" + uri + ",toRead=" + toRead); break; } } } finally { if (is != null) { is.close(); } } } else { os.write(content.getContentAsByteArray()); } } else if (ContentType.TEXT.equals(type) || ContentType.XML.equals(type) || ContentType.JSON.equals(type)) { if (encoding.equals("UTF-8")) { Text t = content.getContentAsText(); os.write(t.getBytes(), 0, t.getLength()); } else { String t = content.getContentAsString(); os.write(t.getBytes(encoding)); } if (LOG.isTraceEnabled()) { Text t = content.getContentAsText(); LOG.trace(t); byte[] bytes = content.getContentAsByteArray(); StringBuilder sb = new StringBuilder(); for (int i = 0; i < bytes.length; i++) { sb.append(Byte.toString(bytes[i])); sb.append(" "); } LOG.trace(sb); } } else { LOG.error("Skipping " + uri + ". Unsupported content type: " + type.name()); } } catch (Exception e) { LOG.error("Error saving: " + uri, e); } finally { if (os != null) { os.close(); } } }