9
9
import one .nio .http .RequestMethod ;
10
10
import one .nio .http .Response ;
11
11
import one .nio .server .AcceptorConfig ;
12
+ import one .nio .util .Utf8 ;
12
13
import ru .vk .itmo .ServiceConfig ;
13
14
import ru .vk .itmo .dao .BaseEntry ;
14
15
import ru .vk .itmo .dao .Entry ;
@@ -44,7 +45,7 @@ private static HttpServerConfig createServerConfig(ServiceConfig serviceConfig)
44
45
@ RequestMethod (Request .METHOD_GET )
45
46
public Response getEntity (@ Param (value = "id" , required = true ) String id ) {
46
47
if (isParamIncorrect (id )) return new Response (Response .BAD_REQUEST , Response .EMPTY );
47
- Entry <MemorySegment > value = dao .get (MemorySegment .ofArray (id . toCharArray ( )));
48
+ Entry <MemorySegment > value = dao .get (MemorySegment .ofArray (Utf8 . toBytes ( id )));
48
49
return value == null ? new Response (Response .NOT_FOUND , Response .EMPTY )
49
50
: Response .ok (value .value ().toArray (ValueLayout .JAVA_BYTE ));
50
51
}
@@ -55,7 +56,7 @@ public Response putEntity(@Param(value = "id", required = true) String id, Reque
55
56
byte [] value = request .getBody ();
56
57
if (isParamIncorrect (id )) return new Response (Response .BAD_REQUEST , Response .EMPTY );
57
58
dao .upsert (new BaseEntry <>(
58
- MemorySegment .ofArray (id . toCharArray ( )),
59
+ MemorySegment .ofArray (Utf8 . toBytes ( id )),
59
60
MemorySegment .ofArray (value )));
60
61
return new Response (Response .CREATED , Response .EMPTY );
61
62
}
@@ -64,7 +65,7 @@ public Response putEntity(@Param(value = "id", required = true) String id, Reque
64
65
@ RequestMethod (Request .METHOD_DELETE )
65
66
public Response deleteEntity (@ Param (value = "id" , required = true ) String id ) {
66
67
if (isParamIncorrect (id )) return new Response (Response .BAD_REQUEST , Response .EMPTY );
67
- dao .upsert (new BaseEntry <>(MemorySegment .ofArray (id . toCharArray ( )), null ));
68
+ dao .upsert (new BaseEntry <>(MemorySegment .ofArray (Utf8 . toBytes ( id )), null ));
68
69
return new Response (Response .ACCEPTED , Response .EMPTY );
69
70
}
70
71
0 commit comments