List of usage examples for java.io ByteArrayOutputStream write
public synchronized void write(int b)
From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java
public static byte[] parseHexProperty(String name, String key) { String TAG = "VCDescriptionFile:parseHexProperty"; String value = key;// w w w .j av a2 s . c o m try { ByteArrayOutputStream out = new ByteArrayOutputStream(); while (value.length() > 0) { out.write(Integer.parseInt(value.substring(0, 2), 16)); value = value.substring(2); } return out.toByteArray(); } catch (Exception e) { e.printStackTrace(); Log.i(TAG, "Property %s is malformed" + name); System.exit(1); return null; } }
From source file:bin.spider.frame.uri.LaxURLCodec.java
/** * Decodes an array of URL safe 7-bit characters into an array of * original bytes. Escaped characters are converted back to their * original representation.//from www .j a va2s . c om * * Differs from URLCodec.decodeUrl() in that it throws no * exceptions; bad or incomplete escape sequences are ignored * and passed into result undecoded. This matches the behavior * of browsers, which will use inconsistently-encoded URIs * in HTTP request-lines. * * @param bytes array of URL safe characters * @return array of original bytes */ public static final byte[] decodeUrlLoose(byte[] bytes) { if (bytes == null) { return null; } ByteArrayOutputStream buffer = new ByteArrayOutputStream(); for (int i = 0; i < bytes.length; i++) { int b = bytes[i]; if (b == '+') { buffer.write(' '); continue; } if (b == '%') { if (i + 2 < bytes.length) { int u = Character.digit((char) bytes[i + 1], 16); int l = Character.digit((char) bytes[i + 2], 16); if (u > -1 && l > -1) { // good encoding int c = ((u << 4) + l); buffer.write((char) c); i += 2; continue; } // else: bad encoding digits, leave '%' in place } // else: insufficient encoding digits, leave '%' in place } buffer.write(b); } return buffer.toByteArray(); }
From source file:net.panthema.BispanningGame.GraphString.java
static int readInt(PushbackReader pr) throws IOException { int c;/* w ww . j a v a 2 s .c o m*/ ByteArrayOutputStream ba = new ByteArrayOutputStream(); while ((c = pr.read()) != 0 && (Character.isDigit(c) || c == '-')) { ba.write(c); } pr.unread(c); try { return Integer.parseInt(ba.toString()); } catch (NumberFormatException e) { throw (new IOException("Error in Graph String: integer format error")); } }
From source file:Main.java
public static byte[] removeBy(int value, byte[] content) { ByteArrayOutputStream out = new ByteArrayOutputStream(); if (content.length > 0) { boolean preisSame = true; // int tailIndex = content.length - 1; for (int i = 0; i < content.length; i++) { if (content[i] != value) { preisSame = false;//ww w . j a v a 2 s . com out.write(content[i]); } else if (content[i] == value && preisSame) { //ignore } else if (i == tailIndex) { } else { out.write(value); preisSame = true; } } } return out.toByteArray(); }
From source file:$.CrmTest.java
private static String getStringFromInputStream(InputStream in) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int c = 0; while ((c = in.read()) != -1) { bos.write(c); }// w w w . j a v a2 s. c o m in.close(); bos.close(); return bos.toString(); }
From source file:org.pmedv.core.util.ResourceUtils.java
/** * Creates a {@link ByteArrayResource} from an input stream * /* w w w.j a va 2 s.c o m*/ * @param is the stream to read from * @return the resource */ @SuppressWarnings("unused") public static ByteArrayResource createResourceFromStream(InputStream is) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] b; try { b = new byte[is.available()]; for (int n; (n = is.read(b)) != -1;) { bos.write(b); } } catch (IOException e) { e.printStackTrace(); } return new ByteArrayResource(bos.toByteArray()); }
From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java
public static byte[] AddandUpdateMDAC(byte[] vCData, short vcEntry, String appName) { String TAG = "VCDescriptionFile:AddandUpdateMDAC"; Log.i(TAG, "Enter"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] VC_EntryBytes = Utils.shortToByteArr(vcEntry); try {// w ww . j a v a2 s. c o m out.write(createTlv(0x4F, Hex.decodeHex(appName.toCharArray()))); out.write(createTlv(0x40, VC_EntryBytes)); return (createTlv(0x72, Utils.append(out.toByteArray(), vCData))); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java
public static byte[] CreateMFData(byte[] vCData, short vCEntry) { String TAG = "VCDescriptionFile:CreateMFData"; Log.i(TAG, "Enter"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] VC_EntryBytes = Utils.shortToByteArr(vCEntry); try {//w w w . j a v a 2 s . c o m out.write(createTlv(0x40, VC_EntryBytes)); out.write(vCData); return (createTlv(0x78, out.toByteArray())); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:com.example.CrmTest.java
private static String getStringFromInputStream(InputStream in) throws Exception { ByteArrayOutputStream bos = new ByteArrayOutputStream(); int c = 0;//from w w w .j av a 2s .co m while ((c = in.read()) != -1) { bos.write(c); } in.close(); bos.close(); return bos.toString(); }
From source file:com.nxp.ltsm.ltsmclient.tools.VCDescriptionFile.java
public static byte[] createVc(byte[] VCData, String appName, short VC_Entry) { String TAG = "VCDescriptionFile:createVC"; Log.i(TAG, "Enter"); ByteArrayOutputStream out = new ByteArrayOutputStream(); byte[] VC_EntryBytes = Utils.shortToByteArr(VC_Entry); try {//from www .j av a 2s . c om out.write(createTlv(0x4F, Hex.decodeHex(appName.toCharArray()))); out.write(createTlv(0x40, VC_EntryBytes)); return (createTlv(0x70, Utils.append(out.toByteArray(), VCData))); } catch (Exception e) { e.printStackTrace(); } return null; }