-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master'
- Loading branch information
Showing
8 changed files
with
556 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>ru.mifi.practice</groupId> | ||
<artifactId>pOOP</artifactId> | ||
<version>2024.2</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<artifactId>vol8</artifactId> | ||
<name>vol8</name> | ||
<description>Модуль №8</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.34</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.google.guava</groupId> | ||
<artifactId>guava</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.mongodb</groupId> | ||
<artifactId>bson</artifactId> | ||
<version>5.2.0</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>2.17.2</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.postgresql</groupId> | ||
<artifactId>postgresql</artifactId> | ||
<version>42.7.3</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package ru.mifi.practice.vol8; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.bson.AbstractBsonWriter; | ||
import org.bson.BsonBinaryReader; | ||
import org.bson.BsonBinaryWriter; | ||
import org.bson.BsonReader; | ||
import org.bson.BsonType; | ||
import ru.mifi.practice.vol8.streaming.Bson; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
|
||
@RequiredArgsConstructor | ||
public final class User { | ||
private final String name; | ||
private final String password; | ||
|
||
public static void main(String[] args) { | ||
User user = new User("bob", "password"); | ||
ByteArrayOutputStream output = new ByteArrayOutputStream(); | ||
try (var bsonOutput = Bson.newOutput(output); AbstractBsonWriter writer = new BsonBinaryWriter(bsonOutput)) { | ||
writer.writeStartDocument(); | ||
writer.writeString("name", user.name); | ||
writer.writeString("password", user.password); | ||
writer.writeEndDocument(); | ||
writer.flush(); | ||
} | ||
byte[] bytes = output.toByteArray(); | ||
try (BsonReader reader = new BsonBinaryReader(Bson.newInput(bytes))) { | ||
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; | ||
break; | ||
} | ||
case STRING: { | ||
String readName = reader.readName(); | ||
if ("name".equals(readName)) { | ||
System.out.println(reader.readString()); | ||
} else if ("password".equals(readName)) { | ||
System.out.println(reader.readString()); | ||
} | ||
break; | ||
} | ||
default: { | ||
String name = reader.readName(); | ||
System.out.println(name); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.