File tree Expand file tree Collapse file tree 4 files changed +13
-9
lines changed
compiled_starters/java/src/main/java
starter_templates/java/src/main/java Expand file tree Collapse file tree 4 files changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ public static void main(String[] args){
1919 try {
2020 byte [] header = Files .readAllBytes (Path .of (databaseFilePath ));
2121
22- // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order
23- int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort ();
22+ // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order.
23+ // '& 0xFFFF' is used to convert the signed short to an unsigned int.
24+ int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort () & 0xFFFF ;
2425
2526 // You can use print statements as follows for debugging, they'll be visible when running tests.
2627 System .out .println ("Logs from your program will appear here!" );
Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ public static void main(String[] args){
1919 try {
2020 byte [] header = Files .readAllBytes (Path .of (databaseFilePath ));
2121
22- // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order
23- int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort ();
22+ // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order.
23+ // '& 0xFFFF' is used to convert the signed short to an unsigned int.
24+ int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort () & 0xFFFF ;
2425
2526 System .out .println ("database page size: " + pageSize );
2627 } catch (IOException e ) {
Original file line number Diff line number Diff line change 1- @@ -1,37 +1,33 @@
1+ @@ -1,38 +1,34 @@
22 import java.io.IOException;
33 import java.nio.ByteBuffer;
44 import java.nio.ByteOrder;
2020 try {
2121 byte[] header = Files.readAllBytes(Path.of(databaseFilePath));
2222
23- // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order
24- int pageSize = ByteBuffer.wrap(header).order(ByteOrder.BIG_ENDIAN).position(16).getShort();
23+ // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order.
24+ // '& 0xFFFF' is used to convert the signed short to an unsigned int.
25+ int pageSize = ByteBuffer.wrap(header).order(ByteOrder.BIG_ENDIAN).position(16).getShort() & 0xFFFF;
2526
2627- // You can use print statements as follows for debugging, they'll be visible when running tests.
2728- System.out.println("Logs from your program will appear here!");
Original file line number Diff line number Diff line change @@ -19,8 +19,9 @@ public static void main(String[] args){
1919 try {
2020 byte [] header = Files .readAllBytes (Path .of (databaseFilePath ));
2121
22- // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order
23- int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort ();
22+ // The page size is stored at the 16th byte offset, using 2 bytes in big-endian order.
23+ // '& 0xFFFF' is used to convert the signed short to an unsigned int.
24+ int pageSize = ByteBuffer .wrap (header ).order (ByteOrder .BIG_ENDIAN ).position (16 ).getShort () & 0xFFFF ;
2425
2526 // You can use print statements as follows for debugging, they'll be visible when running tests.
2627 System .out .println ("Logs from your program will appear here!" );
You can’t perform that action at this time.
0 commit comments