/** reserve at least len bytes at the end of the buffer. * Invalid if len > buffer.length */ public void reserve(int len) throws IOException { if (len > (buf.length - pos)) flushBuffer(); }
public static FastOutputStream wrap(OutputStream sink) { return (sink instanceof FastOutputStream) ? (FastOutputStream)sink : new FastOutputStream(sink); }
public void writeFloat(float val) throws IOException { daos.writeByte(FLOAT); daos.writeFloat(val); }
protected void writeDouble(double val) throws IOException { daos.writeByte(DOUBLE); daos.writeDouble(val); }
public boolean writePrimitive(Object val) throws IOException { if (val == null) { daos.writeByte(NULL); return true; } else if (val instanceof String) { return true; } else if (val instanceof Float) { daos.writeByte(FLOAT); daos.writeFloat(((Float) val).floatValue()); return true; } else if (val instanceof Date) { daos.writeByte(DATE); daos.writeLong(((Date) val).getTime()); return true; } else if (val instanceof Boolean) { if ((Boolean) val) daos.writeByte(BOOL_TRUE); else daos.writeByte(BOOL_FALSE); return true; } else if (val instanceof Double) { daos.writeByte(DOUBLE); daos.writeDouble(((Double) val).doubleValue()); return true; } else if (val instanceof Byte) { daos.writeByte(BYTE); daos.writeByte(((Byte) val).intValue()); return true; } else if (val instanceof Short) { daos.writeByte(SHORT); daos.writeShort(((Short) val).intValue());
if (sindexVersion != null) indexVersion = Long.parseLong(sindexVersion); if (Boolean.parseBoolean(compress)) { fos = new FastOutputStream(new DeflaterOutputStream(out)); } else { fos = new FastOutputStream(out); if (bytesRead <= 0) { writeNothing(); fos.close(); break; fos.writeInt((int) bytesRead); if (useChecksum) { checksum.reset(); checksum.update(buf, 0, (int) bytesRead); fos.writeLong(checksum.getValue()); fos.write(buf, 0, (int) bytesRead); fos.flush(); if (indexVersion != null && (packetsWritten % 5 == 0)) {
public void marshal(NamedList nl, OutputStream os) throws IOException { daos = FastOutputStream.wrap(os); try { daos.writeByte(VERSION); writeNamedList(nl); } finally { daos.flushBuffer(); } }
@Override public void write(DataOutput out) throws IOException { JavaBinCodec codec = new JavaBinCodec(); FastOutputStream daos = FastOutputStream.wrap(DataOutputOutputStream.constructOutputStream(out)); codec.init(daos); try { codec.writeVal(sid); } finally { daos.flushBuffer(); } }
public boolean writePrimitive(Object val) throws IOException { if (val == null) { daos.writeByte(NULL); return true; } else if (val instanceof CharSequence) { return true; } else if (val instanceof Byte) { daos.writeByte(BYTE); daos.writeByte(((Byte) val).intValue()); return true; } else if (val instanceof Short) { daos.writeByte(SHORT); daos.writeShort(((Short) val).intValue()); return true; daos.writeByte(DATE); daos.writeLong(((Date) val).getTime()); return true; } else if (val instanceof Boolean) {
public void write(byte b) throws IOException { if (pos >= buf.length) { written += pos; flush(buf, 0, buf.length); pos=0; } buf[pos++] = b; }
@Override public void writeInt(int v) throws IOException { reserve(4); buf[pos] = (byte)(v>>>24); buf[pos+1] = (byte)(v>>>16); buf[pos+2] = (byte)(v>>>8); buf[pos+3] = (byte)(v); pos+=4; }
@Override public void writeFloat(float v) throws IOException { writeInt(Float.floatToRawIntBits(v)); }
@Override public void writeDouble(double v) throws IOException { writeLong(Double.doubleToRawLongBits(v)); }
@Override public void writeChars(String s) throws IOException { // non-optimized version for (int i=0; i<s.length(); i++) writeChar(s.charAt(i)); }