package com.mongodb;
import org.bson.BasicBSONDecoder;
import java.io.IOException;
import java.io.InputStream;
public class DefaultDBDecoder extends BasicBSONDecoder implements DBDecoder {
@Override
public DBCallback getDBCallback(final DBCollection collection) {
return new DefaultDBCallback(collection);
}
@Override
public DBObject decode(final InputStream input, final DBCollection collection) throws IOException {
DBCallback callback = getDBCallback(collection);
decode(input, callback);
return (DBObject) callback.get();
}
@Override
public DBObject decode(final byte[] bytes, final DBCollection collection) {
DBCallback callback = getDBCallback(collection);
decode(bytes, callback);
return (DBObject) callback.get();
}
@Override
public String toString() {
return String.format("DBDecoder{class=%s}", getClass().getName());
}
public static final DBDecoderFactory FACTORY = new DBDecoderFactory() {
@Override
public DBDecoder create() {
return new DefaultDBDecoder();
}
};
}