Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
Pastor committed Nov 30, 2024
2 parents 9ba98a6 + cbe234e commit 1a9352e
Show file tree
Hide file tree
Showing 8 changed files with 556 additions and 4 deletions.
3 changes: 2 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<module>vol5</module>
<module>vol6</module>
<module>vol7</module>
<module>vol8</module>
</modules>

<dependencyManagement>
Expand Down Expand Up @@ -111,7 +112,7 @@
<dependency>
<groupId>com.puppycrawl.tools</groupId>
<artifactId>checkstyle</artifactId>
<version>10.18.2</version>
<version>10.19.0</version>
</dependency>
</dependencies>
<configuration>
Expand Down
2 changes: 1 addition & 1 deletion vol4/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<description>Модуль №4</description>

<properties>
<dagger.version>2.16</dagger.version>
<dagger.version>2.52</dagger.version>
</properties>

<dependencies>
Expand Down
4 changes: 2 additions & 2 deletions vol5/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.5.0</version>
<version>2.6.0</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand All @@ -63,7 +63,7 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>3.3.4</version>
<version>3.3.5</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
42 changes: 42 additions & 0 deletions vol8/pom.xml
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>
62 changes: 62 additions & 0 deletions vol8/src/main/java/ru/mifi/practice/vol8/User.java
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;
}
}
}
}
}
}
Loading

0 comments on commit 1a9352e

Please sign in to comment.