-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Осокин Дмитрий Hw6 Политех #216
Merged
Merged
Changes from 64 commits
Commits
Show all changes
73 commits
Select commit
Hold shift + click to select a range
0ab3565
hw1 first try
osokindm cdd1344
hw1 first try
osokindm 0bc4a3c
hw1 first try
osokindm 2850402
Merge remote-tracking branch 'upstream/main' into hw2
osokindm 5953064
hw2 first try
osokindm 44fa83b
hw2 first try
osokindm dd8325d
hw2 string templates removed
osokindm 85b3b03
hw2 codeclimate
osokindm 7e63897
hw2 codeclimate
osokindm f04d085
hw2 report
osokindm 361e242
Merge remote-tracking branch 'upstream/main' into hw2
osokindm 1cb5596
Merge remote-tracking branch 'upstream/main' into hw3
osokindm 20e5d6f
Merge remote-tracking branch 'upstream/main' into hw3
osokindm 0e4af77
hw3 codeDrop
osokindm 88dc906
hw3 codeDrop
osokindm 3b9167a
hw3 some fixes
osokindm 161db28
hw3 test fixes and changes using ref
osokindm ac1c7bf
Merge remote-tracking branch 'upstream/main' into hw3
osokindm 6ae531e
hw3 codeclimate fixes
osokindm 61fe433
hw3 codeclimate fixes
osokindm f4de8b4
Merge remote-tracking branch 'upstream/main' into hw3
osokindm d2dc175
hw3 report
osokindm c67d6a5
hw3 report
osokindm 7bf82ce
Merge remote-tracking branch 'upstream/main' into hw3
osokindm fa14300
hw4 codeDrop
osokindm bf8d5cf
Merge remote-tracking branch 'upstream/main' into hw4
osokindm 6e337c9
hw4 codeDrop
osokindm 969e9aa
hw4 works
osokindm 9adbad8
hw4 codeclimate
osokindm 14b117e
hw4 report
osokindm e514f08
hw4 report
osokindm 2c295d7
Merge remote-tracking branch 'upstream/main' into hw4
osokindm eefc94d
codeDrop
osokindm 847631a
codeDrop
osokindm d0d6188
codeDrop
osokindm aca5ac7
codeDrop
osokindm 19bc6c5
codeDrop
osokindm 101be9e
two tests not working
osokindm 3d24854
green tests
osokindm 3f534b2
Merge branch 'main' into hw5
osokindm ec9764e
started refactoring
osokindm f5b7bfe
Merge remote-tracking branch 'origin/hw5' into hw5
osokindm 618b738
refactoring
osokindm 232e37d
code climate
osokindm e30ea9a
code climate
osokindm 4fea109
code climate
osokindm fc29758
code climate
osokindm 5cdd876
code climate
osokindm 29e0ec9
code climate
osokindm 84be982
code climate
osokindm f35bf92
code climate
osokindm 9cab995
code climate
osokindm 24e1725
Merge branch 'main' into hw5
incubos 411ed9b
hw5 report
osokindm 960f2b8
Merge remote-tracking branch 'origin/hw5' into hw5
osokindm 5263319
Merge remote-tracking branch 'upstream/main' into hw5
osokindm 54d892a
hw5 fixes, not all yet
osokindm 1051c92
hw5 fixes, not all yet
osokindm 03d1f7b
hw5 fixes, not all yet
osokindm 6f35013
hw5 fixes
osokindm afc1dbc
hw5 climate
osokindm df974df
hw5 climate
osokindm 21ea0d2
hw5 climate
osokindm be0a6b4
hw6 wip
osokindm 305e85a
hw6 wip
osokindm 68e09ba
hw6
osokindm 70bead5
hw6
osokindm f1f98f2
Merge branch 'main' into hw6
incubos dfa8715
hw6 report'ik
osokindm ad78207
Merge remote-tracking branch 'origin/hw6' into hw6
osokindm b9e28ad
hw6 report'ik
osokindm 7f841ba
Merge branch 'main' into hw6
lamtev b184ffb
Merge branch 'main' into hw6
incubos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
src/main/java/ru/vk/itmo/test/osokindm/ChunkedResponse.java
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,26 @@ | ||
package ru.vk.itmo.test.osokindm; | ||
|
||
import one.nio.http.Response; | ||
import ru.vk.itmo.test.osokindm.dao.Entry; | ||
|
||
import java.lang.foreign.MemorySegment; | ||
import java.util.Iterator; | ||
|
||
public class ChunkedResponse extends Response { | ||
|
||
private static final String CHUNKED_HEADER = "Transfer-Encoding: chunked"; | ||
private static final String CONTENT_TYPE_HEADER = "Content-Type: result-range"; | ||
private final Iterator<Entry<MemorySegment>> rangeResult; | ||
|
||
public ChunkedResponse(String resultCode, Iterator<Entry<MemorySegment>> rangeResult) { | ||
super(resultCode); | ||
super.addHeader(CHUNKED_HEADER); | ||
super.addHeader(CONTENT_TYPE_HEADER); | ||
this.rangeResult = rangeResult; | ||
} | ||
|
||
public Iterator<Entry<MemorySegment>> getResultIterator() { | ||
return rangeResult; | ||
} | ||
|
||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/ru/vk/itmo/test/osokindm/CustomHttpSession.java
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,58 @@ | ||
package ru.vk.itmo.test.osokindm; | ||
|
||
import one.nio.http.HttpServer; | ||
import one.nio.http.HttpSession; | ||
import one.nio.http.Response; | ||
import one.nio.net.Socket; | ||
import ru.vk.itmo.test.osokindm.dao.Entry; | ||
|
||
import java.io.IOException; | ||
import java.lang.foreign.MemorySegment; | ||
import java.lang.foreign.ValueLayout; | ||
import java.nio.ByteBuffer; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Iterator; | ||
|
||
public class CustomHttpSession extends HttpSession { | ||
|
||
private final byte[] CHUNK_SEPARATOR = "\r\n".getBytes(StandardCharsets.UTF_8); | ||
private final byte[] DELIMITER = "\t".getBytes(StandardCharsets.UTF_8); | ||
private final byte[] ZERO = "0".getBytes(StandardCharsets.UTF_8); | ||
|
||
public CustomHttpSession(Socket socket, HttpServer server) { | ||
super(socket, server); | ||
} | ||
|
||
@Override | ||
protected void writeResponse(Response response, boolean includeBody) throws IOException { | ||
if (response instanceof ChunkedResponse) { | ||
super.writeResponse(response, false); | ||
Iterator<Entry<MemorySegment>> iterator = ((ChunkedResponse) response).getResultIterator(); | ||
while (iterator.hasNext()) { | ||
writeChunk(iterator.next()); | ||
} | ||
|
||
super.write(ZERO, 0, ZERO.length); | ||
super.write(CHUNK_SEPARATOR, 0, CHUNK_SEPARATOR.length); | ||
super.write(CHUNK_SEPARATOR, 0, CHUNK_SEPARATOR.length); | ||
} else { | ||
super.writeResponse(response, includeBody); | ||
} | ||
} | ||
|
||
private void writeChunk(Entry<MemorySegment> entry) throws IOException { | ||
byte[] keyBytes = entry.key().toArray(ValueLayout.JAVA_BYTE); | ||
byte[] valueBytes = entry.value().toArray(ValueLayout.JAVA_BYTE); | ||
int entryLength = keyBytes.length + valueBytes.length + DELIMITER.length; | ||
ByteBuffer buffer = ByteBuffer.allocate(entryLength); | ||
buffer.put(Integer.toHexString(entryLength).getBytes(StandardCharsets.UTF_8)); | ||
buffer.put(CHUNK_SEPARATOR); | ||
buffer.put(entry.key().toArray(ValueLayout.JAVA_BYTE)); | ||
buffer.put(DELIMITER); | ||
buffer.put(entry.value().toArray(ValueLayout.JAVA_BYTE)); | ||
buffer.put(CHUNK_SEPARATOR); | ||
|
||
super.write(buffer.array(), 0, buffer.position()); | ||
} | ||
|
||
} |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Здесь имело смысл воспользоваться Pattern Matching for instanceof