Skip to content

Commit

Permalink
Merge pull request #867 from cfredri4/bytes-message-helper
Browse files Browse the repository at this point in the history
BytesMessage helper
  • Loading branch information
belaban authored Nov 20, 2024
2 parents 79d5b0d + e577954 commit 31da6d5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/org/jgroups/BytesMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,15 @@ public BytesMessage setArray(ByteArray buf) {
return this;
}

public byte[] getBytes() {
if(array == null) return null;
if(offset == 0 && length == array.length)
return array;
byte[] tmp=new byte[length];
System.arraycopy(array, offset, tmp, 0, length);
return tmp;
}



/**
Expand Down Expand Up @@ -219,7 +228,7 @@ public <T extends Object> T getObject(ClassLoader loader) {
if(array == null)
return null;
try {
return isFlagSet(Flag.SERIALIZED)? Util.objectFromByteBuffer(array, offset, length, loader) : (T)getArray();
return isFlagSet(Flag.SERIALIZED)? Util.objectFromByteBuffer(array, offset, length, loader) : (T)getBytes();
}
catch(Exception ex) {
throw new IllegalArgumentException(ex);
Expand Down

0 comments on commit 31da6d5

Please sign in to comment.