Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- byte boundaryByte = (byte)10;
- byte byte1 = (byte)0;
- boolean twoInRow = false;
- TByteArrayList byteList = new TByteArrayList();
- while (isRunning) {
- try {
- if (channelThread != null) {
- int nextValue = dataInputStream.read();
- if (nextValue != -1) {
- byte b = (byte) nextValue;
- //System.out.println(b);
- byteList.add(b);
- if (b == boundaryByte) {
- if (byte1 == (byte)0) {
- byte1 = boundaryByte;
- } else if (byte1 == (byte)10 && !twoInRow) {
- twoInRow = true;
- } else if (byte1 == (byte)10 && twoInRow) {
- channelThread.getBytes().add(byteList.toArray());
- byte1 = (byte)0;
- twoInRow = false;
- byteList.clear();
- }
- } else {
- twoInRow = false;
- byte1 = (byte)0;
- }
- }
- try {
- Thread.sleep(1);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- } catch (EOFException e) {
- System.out.println("Channel socket was closed!");
- closeConnection();
- } catch (SocketException e) {
- System.out.println("Channel socket was closed!");
- closeConnection();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement