+ return message;
+ }
+
+ private int getAdditionalHeaderEndIndex(byte[] bytes) {
+ for (String possibleEnd : Lists.newArrayList("]\n", "]\r\n")) {
+ int idx = ByteArray.findByteSequence(bytes, possibleEnd.getBytes(Charsets.UTF_8));
+
+ if (idx != -1) {
+ return idx;
+ }
+ }
+
+ return -1;
+ }
+
+ private boolean startsWithAdditionalHeader(byte[] bytes) {
+ List<String> possibleStarts = Lists.newArrayList("[", "\r\n[", "\n[");
+ for (String possibleStart : possibleStarts) {
+ int i = 0;
+ for (byte b : possibleStart.getBytes(Charsets.UTF_8)) {
+ if(bytes[i]!=b)
+ break;
+
+ return true;
+ }
+ }
+
+ return false;
+ };
+
+ private void logMessage(byte[] bytes) {
+ String s = Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();
+ logger.debug("Parsing message \n{}", s);
+ }
+
+ private String additionalHeaderToString(byte[] bytes) {
+ return Charsets.UTF_8.decode(ByteBuffer.wrap(bytes)).toString();