Skip to content

Commit

Permalink
fix: fix the ByteBuffer's clear method
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyang733 committed Jun 26, 2022
1 parent 1fcb761 commit 191c3f2
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.qcloud.cos</groupId>
<artifactId>hadoop-cos</artifactId>
<version>8.1.3</version>
<version>8.1.4</version>
<packaging>jar</packaging>

<name>Apache Hadoop Tencent Cloud COS Support</name>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/apache/hadoop/fs/CosNConfigKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@InterfaceStability.Unstable
public class CosNConfigKeys extends CommonConfigurationKeys {
public static final String USER_AGENT = "fs.cosn.user.agent";
public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v8.1.3";
public static final String DEFAULT_USER_AGENT = "cos-hadoop-plugin-v8.1.4";

public static final String TENCENT_EMR_VERSION_KEY = "fs.emr.version";

Expand Down
20 changes: 12 additions & 8 deletions src/main/java/org/apache/hadoop/fs/cosn/buffer/CosNByteBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,19 @@ public abstract class CosNByteBuffer implements Closeable {
LoggerFactory.getLogger(CosNByteBuffer.class);

protected ByteBuffer byteBuffer;
private int lastWritePosition;
private int nextWritePosition;

public CosNByteBuffer(ByteBuffer byteBuffer) {
this.byteBuffer = byteBuffer;
this.lastWritePosition = this.byteBuffer.position();
this.nextWritePosition = this.byteBuffer.position();
}

public CosNByteBuffer put(byte b) {
public CosNByteBuffer put(byte b) throws IOException {
if (this.byteBuffer.hasRemaining()) {
throw new IOException("There is no remaining in the buffer.");
}
this.byteBuffer.put(b);
this.lastWritePosition = this.byteBuffer.position();
this.nextWritePosition = this.byteBuffer.position();
return this;
}

Expand All @@ -37,7 +40,7 @@ public CosNByteBuffer put(byte[] src, int offset, int length) throws IOException
}

this.byteBuffer.put(src, offset, length);
this.lastWritePosition = this.byteBuffer.position();
this.nextWritePosition = this.byteBuffer.position();
return this;
}

Expand Down Expand Up @@ -84,6 +87,7 @@ public CosNByteBuffer reset() {

public CosNByteBuffer clear() {
this.byteBuffer.clear();
this.nextWritePosition = 0;
return this;
}

Expand All @@ -98,13 +102,13 @@ public CosNByteBuffer rewind() {
}

public CosNByteBuffer flipRead() {
this.limit(this.lastWritePosition);
this.limit(this.nextWritePosition);
this.position(0);
return this;
}

public CosNByteBuffer flipWrite() {
this.position(this.lastWritePosition);
this.position(this.nextWritePosition);
this.limit(this.byteBuffer.capacity());
return this;
}
Expand All @@ -129,6 +133,6 @@ public void close() throws IOException {
this.byteBuffer.clear();

this.byteBuffer = null;
this.lastWritePosition = -1;
this.nextWritePosition = -1;
}
}

1 comment on commit 191c3f2

@vintmd
Copy link
Collaborator

@vintmd vintmd commented on 191c3f2 Jun 27, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Please sign in to comment.