diff --git a/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java b/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java index a30c52834..b0d79b26c 100644 --- a/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java +++ b/other/java/client/src/main/java/seaweedfs/client/SeaweedOutputStream.java @@ -34,7 +34,7 @@ public class SeaweedOutputStream extends OutputStream { private long outputIndex; private String replication = ""; private String collection = ""; - private long totalBytesWritten = 0; // Track total bytes for debugging + private long totalBytesWritten = 0; // Track total bytes for debugging public SeaweedOutputStream(FilerClient filerClient, final String fullpath) { this(filerClient, fullpath, ""); @@ -90,6 +90,19 @@ public class SeaweedOutputStream extends OutputStream { this.collection = collection; } + /** + * Get the current position in the output stream. + * This returns the total position including both flushed and buffered data. + * + * @return current position (flushed + buffered bytes) + */ + public synchronized long getPos() { + long currentPos = position + buffer.position(); + LOG.info("[DEBUG-2024] 📍 getPos() called: flushedPosition={} bufferPosition={} returning={} path={}", + position, buffer.position(), currentPos, path); + return currentPos; + } + public static String getParentDirectory(String path) { int protoIndex = path.indexOf("://"); if (protoIndex >= 0) { @@ -207,7 +220,7 @@ public class SeaweedOutputStream extends OutputStream { } int bufferPosBeforeFlush = buffer.position(); - LOG.info("[DEBUG-2024] 🔒 close START: path={} position={} buffer.position()={} totalBytesWritten={}", + LOG.info("[DEBUG-2024] 🔒 close START: path={} position={} buffer.position()={} totalBytesWritten={}", path, position, bufferPosBeforeFlush, totalBytesWritten); try { flushInternal();