forked from traccar/traccar
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
86 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package org.traccar; | ||
|
||
import org.jboss.netty.buffer.ChannelBuffer; | ||
import org.jboss.netty.buffer.ChannelBuffers; | ||
import org.jboss.netty.handler.codec.frame.DelimiterBasedFrameDecoder; | ||
|
||
public class CharacterDelimiterFrameDecoder extends DelimiterBasedFrameDecoder { | ||
|
||
private static ChannelBuffer createDelimiter(char delimiter) { | ||
byte buf[] = { (byte) delimiter }; | ||
return ChannelBuffers.wrappedBuffer(buf); | ||
} | ||
|
||
private static ChannelBuffer createDelimiter(String delimiter) { | ||
byte buf[] = new byte[delimiter.length()]; | ||
for (int i = 0; i < delimiter.length(); i++) { | ||
buf[i] = (byte) delimiter.charAt(i); | ||
} | ||
return ChannelBuffers.wrappedBuffer(buf); | ||
} | ||
|
||
private static ChannelBuffer[] convertDelimiters(String[] delimiters) { | ||
ChannelBuffer result[] = new ChannelBuffer[delimiters.length]; | ||
for (int i = 0; i < delimiters.length; i++) { | ||
result[i] = createDelimiter(delimiters[i]); | ||
} | ||
return result; | ||
} | ||
|
||
public CharacterDelimiterFrameDecoder(int maxFrameLength, char delimiter) { | ||
super(maxFrameLength, createDelimiter(delimiter)); | ||
} | ||
|
||
public CharacterDelimiterFrameDecoder(int maxFrameLength, String delimiter) { | ||
super(maxFrameLength, createDelimiter(delimiter)); | ||
} | ||
|
||
public CharacterDelimiterFrameDecoder(int maxFrameLength, String... delimiters) { | ||
super(maxFrameLength, convertDelimiters(delimiters)); | ||
} | ||
|
||
} |
Oops, something went wrong.