/** * Returns a byte array containing the UTF encoding of the given string. */ public static byte[] toUtf(String s) throws UTFDataFormatException { try { OptimizedByteArrayOutputStream bout = new OptimizedByteArrayOutputStream(s.length()); DataOutput dout = new DataOutputStream(bout); dout.writeUTF(s); return bout.toByteArray(); } catch (UTFDataFormatException e) { throw e; } catch (IOException e) { throw new AssertionError(e); } }
/** * Writes the specified byte to this byte array output stream. * * @param b the byte to be written. */ public void write(int b) { ensureCapacity(1); _buffer[_count++] = (byte) b; }
/** * Set stream buffer, and reset the counter. * * @param buf new buffer */ public void setBuffer(byte[] buf) { setBuffer(buf, 0); }
return; OptimizedByteArrayOutputStream bByteOut = new OptimizedByteArrayOutputStream(); bByteOut.writeByte(buildFlag()); OptimizedByteArrayOutputStream lByteOut = new OptimizedByteArrayOutputStream(); lByteOut.writeByte(buildFlag()); OutputStream bout = bByteOut; if (USE_GZIP) { bout.close(); lout.close(); objBytes = bByteOut.toByteArray(); locBytes = (out.hadAnnotations() ? lByteOut.toByteArray() : null);
/** * Computes a SHA-1 digest from the hash of the superclass, if there is a superclass, followed * by the name of this class, followed by the name and type for each field, if any, declared by * this class and ordered alphabetically by field name. The first 8 bytes of the digest are * used to form the 64-bit hash value for this type. */ private void computeHash() throws IOException, NoSuchAlgorithmException { hash = 0; MessageDigest md = MessageDigest.getInstance("SHA"); DataOutputStream out = new DataOutputStream( new DigestOutputStream(new OptimizedByteArrayOutputStream(127), md)); out.writeUTF(name); out.flush(); byte[] digest = md.digest(); for (int i = Math.min(8, digest.length); --i >= 0; ) { hash += ((long) (digest[i] & 0xFF)) << (i * 8); } }
OptimizedByteArrayOutputStream baos = new OptimizedByteArrayOutputStream(); baos.writeByte(buildFlag()); OutputStream os = baos; if (USE_GZIP) { oos.flush(); os.close(); byte[] bytes = baos.toByteArray(); OptimizedByteArrayInputStream bais = new OptimizedByteArrayInputStream(bytes); byte flags = bais.readByte();
MessageDigest md = MessageDigest.getInstance("SHA"); DataOutputStream out = new DataOutputStream( new DigestOutputStream(new OptimizedByteArrayOutputStream(127), md)); if (superclass != null) out.writeLong(superclass.hash);
OptimizedByteArrayOutputStream baos = new OptimizedByteArrayOutputStream(); baos.writeByte(buildFlag()); OutputStream os = baos; if (USE_GZIP) { oos.flush(); os.close(); byte[] bytes = baos.toByteArray(); OptimizedByteArrayInputStream bais = new OptimizedByteArrayInputStream(bytes); byte flags = bais.readByte();
proxyMarshalledObject = proxyMarshalledInstance.convertToMarshalledObject(); OptimizedByteArrayOutputStream os = new OptimizedByteArrayOutputStream(); MarshalOutputStream oos = new MarshalOutputStream(os, Collections.EMPTY_SET); oos.writeObject(proxy); oos.close(); proxyRegistrarBytes = os.toByteArray();
public void writeByte(byte b) { ensureCapacity(1); _buffer[_count++] = b; }
/** * Writes <code>len</code> bytes from the specified byte array starting at offset * <code>off</code> to this byte array output stream. * * @param b the data. * @param off the start offset in the data. * @param len the number of bytes to write. */ public void write(byte b[], int off, int len) { if (len == 0) return; ensureCapacity(len); System.arraycopy(b, off, _buffer, _count, len); _count += len; }