Skip to content

Commit

Permalink
Headers: added delimiters() to delimit headers in printHeaders()
Browse files Browse the repository at this point in the history
  • Loading branch information
belaban committed Nov 18, 2024
1 parent 2972922 commit 0c00066
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions src/org/jgroups/util/Headers.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,17 @@
*/
public final class Headers {
private static final int RESIZE_INCR=3;
private static String BEGIN_DELIM=null, END_DELIM=null;

private Headers() {
throw new InstantiationError( "Must not instantiate this class" );
}

public static void delimiters(String begin, String end) {
BEGIN_DELIM=begin;
END_DELIM=end;
}

/**
* Returns the header associated with an ID
* @param id The ID
Expand Down Expand Up @@ -71,7 +77,6 @@ public static <T extends Header> T getHeader(final Header[] hdrs, short ... ids)
return null;
}


public static Map<Short,Header> getHeaders(final Header[] hdrs) {
if(hdrs == null)
return new HashMap<>();
Expand Down Expand Up @@ -99,12 +104,16 @@ public static String printHeaders(final Header[] hdrs) {
sb.append(", ");
Class<?> clazz=ClassConfigurator.getProtocol(id);
String name=clazz != null? clazz.getSimpleName() : Short.toString(id);
sb.append(name).append(": ").append(hdr);
sb.append(name).append(": ");
if(BEGIN_DELIM != null)
sb.append(BEGIN_DELIM);
sb.append(hdr);
if(END_DELIM != null)
sb.append(END_DELIM);
}
return sb.toString();
}


/**
* Adds hdr at the next available slot. If none is available, the headers array passed in will be copied and the copy
* returned
Expand Down Expand Up @@ -152,7 +161,6 @@ public static void writeHeaders(Header[] hdrs, DataOutput out) throws IOExceptio
}
}


public static Header[] readHeaders(DataInput in) throws IOException, ClassNotFoundException {
int len=in.readShort();
if(len == 0)
Expand All @@ -166,10 +174,7 @@ public static Header[] readHeaders(DataInput in) throws IOException, ClassNotFou
return headers;
}


/**
* Increases the capacity of the array and copies the contents of the old into the new array
*/
/** Increases the capacity of the array and copies the contents of the old into the new array */
public static Header[] resize(final Header[] headers) {
int new_capacity=headers.length + RESIZE_INCR;
Header[] new_hdrs=new Header[new_capacity];
Expand Down

0 comments on commit 0c00066

Please sign in to comment.