@Override public String toString() { return getClass().getName() + " size: " + size() + " pos: " + getPosition(); }
@Override public void writeString(final String str) { writeInt(0); // making space for size int strLen = writeCharacters(str, false); writeInt32(getPosition() - strLen - 4, strLen); }
/** * Encodes a {@code BSONObject}. This is for the higher level api calls. * * @param document the document to encode * @return the number of characters in the encoding */ @Override public int putObject(final BSONObject document) { int startPosition = getOutputBuffer().getPosition(); bsonWriter.writeStartDocument(); if (isTopLevelDocument() && document.containsField("_id")) { _putObjectField("_id", document.get("_id")); } for (final String key : document.keySet()) { if (isTopLevelDocument() && key.equals("_id")) { continue; } _putObjectField(key, document.get(key)); } bsonWriter.writeEndDocument(); return getOutputBuffer().getPosition() - startPosition; }
@Override public String toString() { return getClass().getName() + " size: " + size() + " pos: " + getPosition(); } }
private void putMap(String name, Map m) { this._put(3, name); int sizePos = this._buf.getPosition(); this._buf.writeInt(0); Iterator var4 = m.entrySet().iterator(); while(var4.hasNext()) { Entry entry = (Entry)var4.next(); this._putObjectField(entry.getKey().toString(), entry.getValue()); } this._buf.write(0); this._buf.writeInt(sizePos, this._buf.getPosition() - sizePos); }
private void putArray(String name, Object array) { _put(ARRAY, name); final int sizePos = _buf.getPosition(); _buf.writeInt(0); int size = Array.getLength(array); for (int i = 0; i < size; i++) _putObjectField(String.valueOf(i), Array.get(array, i)); _buf.write(EOO); _buf.writeInt(sizePos, _buf.getPosition() - sizePos); }
private void putMap(String name, Map m) { _put(OBJECT, name); final int sizePos = _buf.getPosition(); _buf.writeInt(0); for (Map.Entry entry : (Set<Map.Entry>) m.entrySet()) _putObjectField(entry.getKey().toString(), entry.getValue()); _buf.write(EOO); _buf.writeInt(sizePos, _buf.getPosition() - sizePos); }
private void putIterable(String name, Iterable l) { this._put(4, name); int sizePos = this._buf.getPosition(); this._buf.writeInt(0); int i = 0; for(Iterator var5 = l.iterator(); var5.hasNext(); ++i) { Object obj = var5.next(); this._putObjectField(String.valueOf(i), obj); } this._buf.write(0); this._buf.writeInt(sizePos, this._buf.getPosition() - sizePos); }
private void putArray(String name, Object array) { this._put(4, name); int sizePos = this._buf.getPosition(); this._buf.writeInt(0); int size = Array.getLength(array); for(int i = 0; i < size; ++i) { this._putObjectField(String.valueOf(i), Array.get(array, i)); } this._buf.write(0); this._buf.writeInt(sizePos, this._buf.getPosition() - sizePos); }
private void putIterable(String name, Iterable l) { _put(ARRAY, name); final int sizePos = _buf.getPosition(); _buf.writeInt(0); int i = 0; for (Object obj : l) { _putObjectField(String.valueOf(i), obj); i++; } _buf.write(EOO); _buf.writeInt(sizePos, _buf.getPosition() - sizePos); }
private void putBinary(String name, int type, byte[] data) { _put(BINARY, name); int totalLen = data.length; if (type == B_BINARY) totalLen += 4; _buf.writeInt(totalLen); _buf.write(type); if (type == B_BINARY) _buf.writeInt(totalLen - 4); int before = _buf.getPosition(); _buf.write(data); int after = _buf.getPosition(); // com.mongodb.util.MyAsserts.assertEquals( after - before , data.length // ); }
protected void _putValueString(String s) { int lenPos = _buf.getPosition(); _buf.writeInt(0); // making space for size int strLen = _put(s); _buf.writeInt(lenPos, strLen); }
private void putBinary(String name, int type, byte[] data) { this._put(5, name); int totalLen = data.length; if(type == 2) { totalLen += 4; } this._buf.writeInt(totalLen); this._buf.write(type); if(type == 2) { this._buf.writeInt(totalLen - 4); } int before = this._buf.getPosition(); this._buf.write(data); int after = this._buf.getPosition(); }
protected void putCode(String name, Code code) { this._put(13, name); int temp = this._buf.getPosition(); this._putValueString(code.getCode()); }
protected void putCode(String name, Code code) { _put(CODE, name); int temp = _buf.getPosition(); _putValueString(code.getCode()); }
public void writeInt(int pos, int x) { final int save = getPosition(); setPosition(pos); writeInt(x); setPosition(save); }
final int start = _buf.getPosition(); if (handleSpecialObjects(name, o)) return _buf.getPosition() - start; final int sizePos = _buf.getPosition(); _buf.writeInt(0); // leaving space for this. set it at the end _buf.writeInt(sizePos, _buf.getPosition() - sizePos); return _buf.getPosition() - start;
protected void putCodeWScope(String name, CodeWScope code) { _put(CODE_W_SCOPE, name); int temp = _buf.getPosition(); _buf.writeInt(0); _putValueString(code.getCode()); putObject(code.getScope()); _buf.writeInt(temp, _buf.getPosition() - temp); }
protected void putCodeWScope(String name, CodeWScope code) { this._put(15, name); int temp = this._buf.getPosition(); this._buf.writeInt(0); this._putValueString(code.getCode()); this.putObject(code.getScope()); this._buf.writeInt(temp, this._buf.getPosition() - temp); }
throw new NullPointerException("can\'t save a null object"); } else { int start = this._buf.getPosition(); byte myType = 3; if(o instanceof List) { return this._buf.getPosition() - start; } else { if(name != null) { int sizePos = this._buf.getPosition(); this._buf.writeInt(0); List transientFields = null; this._buf.writeInt(sizePos, this._buf.getPosition() - sizePos); return this._buf.getPosition() - start;