github-advanced-security[bot] commented on code in PR #954:
URL: 
https://github.com/apache/incubator-baremaps/pull/954#discussion_r2029485595


##########
baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.pmtiles;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Serializer for PMTiles Entry objects.
+ */
+class EntrySerializer implements Serializer<List<Entry>> {
+
+  private final VarIntSerializer varIntSerializer;
+
+  /**
+   * Constructs a new EntrySerializer.
+   */
+  EntrySerializer() {
+    this.varIntSerializer = new VarIntSerializer();
+  }
+
+  /**
+   * Serializes a list of entries to an output stream.
+   *
+   * @param entries the entries to serialize
+   * @param output the output stream to write to
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public void serialize(List<Entry> entries, OutputStream output) throws 
IOException {
+    var buffer = ByteBuffer.allocate(entries.size() * 48);

Review Comment:
   ## Unread local variable
   
   Variable 'ByteBuffer buffer' is never read.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1682)



##########
baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.pmtiles;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Serializer for PMTiles Entry objects.
+ */
+class EntrySerializer implements Serializer<List<Entry>> {
+
+  private final VarIntSerializer varIntSerializer;
+
+  /**
+   * Constructs a new EntrySerializer.
+   */
+  EntrySerializer() {
+    this.varIntSerializer = new VarIntSerializer();
+  }
+
+  /**
+   * Serializes a list of entries to an output stream.
+   *
+   * @param entries the entries to serialize
+   * @param output the output stream to write to
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public void serialize(List<Entry> entries, OutputStream output) throws 
IOException {
+    var buffer = ByteBuffer.allocate(entries.size() * 48);
+    varIntSerializer.writeVarInt(output, entries.size());
+
+    // Write tileIds as deltas
+    long lastId = 0;
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getTileId() - lastId);
+      lastId = entry.getTileId();
+    }
+
+    // Write run lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getRunLength());
+    }
+
+    // Write lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getLength());
+    }
+
+    // Write offsets (with RLE compression)
+    for (int i = 0; i < entries.size(); i++) {
+      Entry entry = entries.get(i);
+      if (i > 0
+          && entry.getOffset() == entries.get(i - 1).getOffset() + 
entries.get(i - 1).getLength()) {
+        varIntSerializer.writeVarInt(output, 0);
+      } else {
+        varIntSerializer.writeVarInt(output, entry.getOffset() + 1);
+      }
+    }
+  }
+
+  /**
+   * Deserializes a list of entries from an input stream.
+   *
+   * @param input the input stream to read from
+   * @return the deserialized list of entries
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public List<Entry> deserialize(InputStream input) throws IOException {
+    long numEntries = varIntSerializer.readVarInt(input);
+    List<Entry> entries = new ArrayList<>((int) numEntries);
+
+    // Read tileIds
+    long lastId = 0;
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      lastId = lastId + value;
+      Entry entry = Entry.builder().tileId(lastId).build();
+      entries.add(entry);
+    }
+
+    // Read run lengths
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      entries.get(i).setRunLength(value);
+    }
+
+    // Read lengths
+    for (int i = 0; i < numEntries; i++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1685)



##########
baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.pmtiles;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Serializer for PMTiles Entry objects.
+ */
+class EntrySerializer implements Serializer<List<Entry>> {
+
+  private final VarIntSerializer varIntSerializer;
+
+  /**
+   * Constructs a new EntrySerializer.
+   */
+  EntrySerializer() {
+    this.varIntSerializer = new VarIntSerializer();
+  }
+
+  /**
+   * Serializes a list of entries to an output stream.
+   *
+   * @param entries the entries to serialize
+   * @param output the output stream to write to
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public void serialize(List<Entry> entries, OutputStream output) throws 
IOException {
+    var buffer = ByteBuffer.allocate(entries.size() * 48);
+    varIntSerializer.writeVarInt(output, entries.size());
+
+    // Write tileIds as deltas
+    long lastId = 0;
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getTileId() - lastId);
+      lastId = entry.getTileId();
+    }
+
+    // Write run lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getRunLength());
+    }
+
+    // Write lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getLength());
+    }
+
+    // Write offsets (with RLE compression)
+    for (int i = 0; i < entries.size(); i++) {
+      Entry entry = entries.get(i);
+      if (i > 0
+          && entry.getOffset() == entries.get(i - 1).getOffset() + 
entries.get(i - 1).getLength()) {
+        varIntSerializer.writeVarInt(output, 0);
+      } else {
+        varIntSerializer.writeVarInt(output, entry.getOffset() + 1);
+      }
+    }
+  }
+
+  /**
+   * Deserializes a list of entries from an input stream.
+   *
+   * @param input the input stream to read from
+   * @return the deserialized list of entries
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public List<Entry> deserialize(InputStream input) throws IOException {
+    long numEntries = varIntSerializer.readVarInt(input);
+    List<Entry> entries = new ArrayList<>((int) numEntries);
+
+    // Read tileIds
+    long lastId = 0;
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      lastId = lastId + value;
+      Entry entry = Entry.builder().tileId(lastId).build();
+      entries.add(entry);
+    }
+
+    // Read run lengths
+    for (int i = 0; i < numEntries; i++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1684)



##########
baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.pmtiles;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Serializer for PMTiles Entry objects.
+ */
+class EntrySerializer implements Serializer<List<Entry>> {
+
+  private final VarIntSerializer varIntSerializer;
+
+  /**
+   * Constructs a new EntrySerializer.
+   */
+  EntrySerializer() {
+    this.varIntSerializer = new VarIntSerializer();
+  }
+
+  /**
+   * Serializes a list of entries to an output stream.
+   *
+   * @param entries the entries to serialize
+   * @param output the output stream to write to
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public void serialize(List<Entry> entries, OutputStream output) throws 
IOException {
+    var buffer = ByteBuffer.allocate(entries.size() * 48);
+    varIntSerializer.writeVarInt(output, entries.size());
+
+    // Write tileIds as deltas
+    long lastId = 0;
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getTileId() - lastId);
+      lastId = entry.getTileId();
+    }
+
+    // Write run lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getRunLength());
+    }
+
+    // Write lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getLength());
+    }
+
+    // Write offsets (with RLE compression)
+    for (int i = 0; i < entries.size(); i++) {
+      Entry entry = entries.get(i);
+      if (i > 0
+          && entry.getOffset() == entries.get(i - 1).getOffset() + 
entries.get(i - 1).getLength()) {
+        varIntSerializer.writeVarInt(output, 0);
+      } else {
+        varIntSerializer.writeVarInt(output, entry.getOffset() + 1);
+      }
+    }
+  }
+
+  /**
+   * Deserializes a list of entries from an input stream.
+   *
+   * @param input the input stream to read from
+   * @return the deserialized list of entries
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public List<Entry> deserialize(InputStream input) throws IOException {
+    long numEntries = varIntSerializer.readVarInt(input);
+    List<Entry> entries = new ArrayList<>((int) numEntries);
+
+    // Read tileIds
+    long lastId = 0;
+    for (int i = 0; i < numEntries; i++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1683)



##########
baremaps-pmtiles/src/main/java/org/apache/baremaps/pmtiles/EntrySerializer.java:
##########
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to you under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.baremaps.pmtiles;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.ByteBuffer;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Serializer for PMTiles Entry objects.
+ */
+class EntrySerializer implements Serializer<List<Entry>> {
+
+  private final VarIntSerializer varIntSerializer;
+
+  /**
+   * Constructs a new EntrySerializer.
+   */
+  EntrySerializer() {
+    this.varIntSerializer = new VarIntSerializer();
+  }
+
+  /**
+   * Serializes a list of entries to an output stream.
+   *
+   * @param entries the entries to serialize
+   * @param output the output stream to write to
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public void serialize(List<Entry> entries, OutputStream output) throws 
IOException {
+    var buffer = ByteBuffer.allocate(entries.size() * 48);
+    varIntSerializer.writeVarInt(output, entries.size());
+
+    // Write tileIds as deltas
+    long lastId = 0;
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getTileId() - lastId);
+      lastId = entry.getTileId();
+    }
+
+    // Write run lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getRunLength());
+    }
+
+    // Write lengths
+    for (Entry entry : entries) {
+      varIntSerializer.writeVarInt(output, entry.getLength());
+    }
+
+    // Write offsets (with RLE compression)
+    for (int i = 0; i < entries.size(); i++) {
+      Entry entry = entries.get(i);
+      if (i > 0
+          && entry.getOffset() == entries.get(i - 1).getOffset() + 
entries.get(i - 1).getLength()) {
+        varIntSerializer.writeVarInt(output, 0);
+      } else {
+        varIntSerializer.writeVarInt(output, entry.getOffset() + 1);
+      }
+    }
+  }
+
+  /**
+   * Deserializes a list of entries from an input stream.
+   *
+   * @param input the input stream to read from
+   * @return the deserialized list of entries
+   * @throws IOException if an I/O error occurs
+   */
+  @Override
+  public List<Entry> deserialize(InputStream input) throws IOException {
+    long numEntries = varIntSerializer.readVarInt(input);
+    List<Entry> entries = new ArrayList<>((int) numEntries);
+
+    // Read tileIds
+    long lastId = 0;
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      lastId = lastId + value;
+      Entry entry = Entry.builder().tileId(lastId).build();
+      entries.add(entry);
+    }
+
+    // Read run lengths
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      entries.get(i).setRunLength(value);
+    }
+
+    // Read lengths
+    for (int i = 0; i < numEntries; i++) {
+      long value = varIntSerializer.readVarInt(input);
+      entries.get(i).setLength(value);
+    }
+
+    // Read offsets
+    for (int i = 0; i < numEntries; i++) {

Review Comment:
   ## Comparison of narrow type with wide type in loop condition
   
   Comparison between [expression](1) of type int and [expression](2) of wider 
type long.
   
   [Show more 
details](https://github.com/apache/incubator-baremaps/security/code-scanning/1686)



-- 
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]

Reply via email to