Skip to content

Commit

Permalink
BytesMessage helper
Browse files Browse the repository at this point in the history
This change adds a helper to get the bytes from BytesMessage. Borrowed from ByteArray.
  • Loading branch information
cfredri4 committed Nov 19, 2024
1 parent 79d5b0d commit e577954
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 e577954

Please sign in to comment.