/** 将byte数组写入到指定<code>OutputStream</code>中。 */ public static void writeBytes(ByteArray bytes, OutputStream out, boolean closeOut) throws IOException { try { out.write(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength()); out.flush(); } finally { if (closeOut) { try { out.close(); } catch (IOException e) { } } } } }
/** 取得当前时间,加上随机数。 */ private byte[] getRandomizedTime() { long jvmId = System.currentTimeMillis(); long random = new SecureRandom().nextLong(); // 取得上述ID的bytes,并转化成字符串 ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeLong(jvmId); dos.writeLong(random); } catch (Exception e) { } return baos.toByteArray().toByteArray(); }
public ByteArray toByteArray() { shared = true; return new ByteArray(buffer, 0, index); }
ByteArray bytes = popByteBuffer(); bytes.writeTo(ostream);
ByteArray bytes = popByteBuffer(); bytes.writeTo(ostream);
/** 将byte数组写入到指定<code>OutputStream</code>中。 */ public static void writeBytes(ByteArray bytes, OutputStream out, boolean closeOut) throws IOException { try { out.write(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength()); out.flush(); } finally { if (closeOut) { try { out.close(); } catch (IOException e) { } } } } }
/** 取得当前时间,加上随机数。 */ private byte[] getRandomizedTime() { long jvmId = System.currentTimeMillis(); long random = new SecureRandom().nextLong(); // 取得上述ID的bytes,并转化成字符串 ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeLong(jvmId); dos.writeLong(random); } catch (Exception e) { } return baos.toByteArray().toByteArray(); }
public ByteArray toByteArray() { shared = true; return new ByteArray(buffer, 0, index); }
ByteArray bytes = popByteBuffer(); bytes.writeTo(ostream);
/** 将byte数组写入到指定<code>OutputStream</code>中。 */ public static void writeBytes(ByteArray bytes, OutputStream out, boolean closeOut) throws IOException { try { out.write(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength()); out.flush(); } finally { if (closeOut) { try { out.close(); } catch (IOException e) { } } } } }
/** 取得当前时间,加上随机数。 */ private byte[] getRandomizedTime() { long jvmId = System.currentTimeMillis(); long random = new SecureRandom().nextLong(); // 取得上述ID的bytes,并转化成字符串 ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); try { dos.writeLong(jvmId); dos.writeLong(random); } catch (Exception e) { } return baos.toByteArray().toByteArray(); }
public ByteArray toByteArray() { shared = true; return new ByteArray(buffer, 0, index); }
@Override public void flush() throws IOException { ByteArray bytes = buffer.toByteArray(); if (bytes.getLength() > 0) { ByteArrayInputStream inputBytes = new ByteArrayInputStream(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength()); InputStreamReader reader = new InputStreamReader(inputBytes, charset); StreamUtil.io(reader, writer, true, false); writer.flush(); buffer.reset(); } }
private byte[] decompress(byte[] data) throws SessionValueEncoderException { if (!doCompress()) { return data; } ByteArrayInputStream bais = new ByteArrayInputStream(data); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); try { return StreamUtil.readBytes(iis, true).toByteArray(); } catch (Exception e) { throw new SessionValueEncoderException(e); } finally { inf.end(); } }
/** 将byte数组写入到指定<code>OutputStream</code>中。 */ public static void writeBytes(byte[] bytes, OutputStream out, boolean closeOut) throws IOException { writeBytes(new ByteArray(bytes), out, closeOut); }
@Override public void flush() throws IOException { ByteArray bytes = buffer.toByteArray(); if (bytes.getLength() > 0) { ByteArrayInputStream inputBytes = new ByteArrayInputStream(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength()); InputStreamReader reader = new InputStreamReader(inputBytes, charset); StreamUtil.io(reader, writer, true, false); writer.flush(); buffer.reset(); } }
private byte[] decompress(byte[] data) throws SessionValueEncoderException { if (!doCompress()) { return data; } ByteArrayInputStream bais = new ByteArrayInputStream(data); Inflater inf = new Inflater(false); InflaterInputStream iis = new InflaterInputStream(bais, inf); try { return StreamUtil.readBytes(iis, true).toByteArray(); } catch (Exception e) { throw new SessionValueEncoderException(e); } finally { inf.end(); } }
/** 将byte数组写入到指定<code>OutputStream</code>中。 */ public static void writeBytes(byte[] bytes, OutputStream out, boolean closeOut) throws IOException { writeBytes(new ByteArray(bytes), out, closeOut); }
/** 将javamail邮件对象转换成文本形式,其格式为标准的<code>.eml</code>格式。 */ public static String toString(Message message, String javaCharset) throws MessagingException, UnsupportedEncodingException { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); try { message.writeTo(ostream); } catch (IOException e) { unexpectedException(e); } finally { ostream.close(); } ByteArray bytes = ostream.toByteArray(); javaCharset = getJavaCharset(javaCharset); return new String(bytes.getRawBytes(), bytes.getOffset(), bytes.getLength(), javaCharset); }
byte[] plaintext = baos.toByteArray().toByteArray();