smengcl commented on code in PR #4584:
URL: https://github.com/apache/ozone/pull/4584#discussion_r1195744685


##########
hadoop-hdds/rocks-native/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedSSTDumpIterator.java:
##########
@@ -86,51 +81,58 @@ public ManagedSSTDumpIterator(ManagedSSTDumpTool 
sstDumpTool,
    * @return Optional of the integer empty if no integer exists
    */
   private Optional<Integer> getNextNumberInStream() throws IOException {
-    StringBuilder value = new StringBuilder();
-    int val;
-    while ((val = processOutput.read()) != -1) {
-      if (val >= '0' && val <= '9') {
-        value.append((char) val);
-      } else if (value.length() > 0) {
-        break;
-      }
+    int n = processOutput.read(intBuffer, 0, 4);
+    if (n == 4) {
+      return Optional.of(ByteBuffer.wrap(intBuffer).getInt());
+    } else if (n >= 0) {
+      throw new IllegalStateException(String.format("Integer expects " +
+          "4 bytes to be read from the stream, but read only %d bytes", n));
     }
-    return value.length() > 0 ? Optional.of(Integer.valueOf(value.toString()))
-        : Optional.empty();
+    return Optional.empty();
   }
 
-  /**
-   * Reads the next n chars from the stream & makes a string.
-   *
-   * @param numberOfChars
-   * @return String of next chars read
-   * @throws IOException
-   */
-  private String readNextNumberOfCharsFromStream(int numberOfChars)
-      throws IOException {
-    StringBuilder value = new StringBuilder();
-    while (numberOfChars > 0) {
-      int noOfCharsRead = processOutput.read(charBuffer, 0,
-          Math.min(numberOfChars, charBuffer.length));
-      if (noOfCharsRead == -1) {
-        break;
+  private Optional<byte[]> getNextByteArray() throws IOException {
+    Optional<Integer> size = getNextNumberInStream();
+    if (size.isPresent()) {
+      byte[] b = new byte[size.get()];

Review Comment:
   debug logging the byte array size
   
   ```suggestion
       if (size.isPresent()) {
         if (LOG.isDebugEnabled()) {
           LOG.debug("Size of byte array: {}", size.get());
         }
         byte[] b = new byte[size.get()];
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to