Skip to content

Commit

Permalink
V8
Browse files Browse the repository at this point in the history
  • Loading branch information
Pastor committed Nov 1, 2024
1 parent 00f748f commit 14f2c5b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 5 additions & 1 deletion vol8/src/main/java/ru/mifi/practice/vol8/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,15 @@ public static void main(String[] args) {
byte[] bytes = output.toByteArray();
try (BsonReader reader = new BsonBinaryReader(new Bson.BsonInputStream(
new ByteArrayInputStream(bytes)))) {
reader.readStartDocument();
boolean reading = true;
while (reading) {
BsonType type = reader.readBsonType();
switch (type) {
case DOCUMENT: {
reader.readStartDocument();
System.out.println("Start document");
break;
}
case END_OF_DOCUMENT: {
System.out.println("End of document");
reading = false;
Expand Down
8 changes: 5 additions & 3 deletions vol8/src/main/java/ru/mifi/practice/vol8/streaming/Bson.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

public final class Bson {
public static final class BsonInputStream implements BsonInput {
private static final int READ_LIMIT = 4096;
private static final String[] ONE_BYTE_ASCII_STRINGS = new String[Byte.MAX_VALUE + 1];

static {
Expand Down Expand Up @@ -122,7 +123,7 @@ public ObjectId readObjectId() {
@Override
public String readCString() {
int mark = getPosition();
stream.mark(1024);
stream.mark(READ_LIMIT);
skipCString();
int size = getPosition();
stream.reset();
Expand Down Expand Up @@ -182,11 +183,12 @@ private void ensureAvailable(final int bytesNeeded) {

private static final class PosBufferedInputStream extends BufferedInputStream {

public PosBufferedInputStream(InputStream in) {
private PosBufferedInputStream(InputStream in) {
super(in);
}

public int getPosition() {
@SuppressWarnings("PMD.UnusedPrivateMethod")
private int getPosition() {
return pos;
}
}
Expand Down

0 comments on commit 14f2c5b

Please sign in to comment.