Advertisement
Guest User

Untitled

a guest
Jan 24th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1.             byte boundaryByte = (byte)10;
  2.             byte byte1 = (byte)0;
  3.             boolean twoInRow = false;
  4.             TByteArrayList byteList = new TByteArrayList();
  5.             while (isRunning) {
  6.                 try {
  7.                     if (channelThread != null) {
  8.                         int nextValue = dataInputStream.read();
  9.                         if (nextValue != -1) {
  10.                             byte b = (byte) nextValue;
  11.                             //System.out.println(b);
  12.                             byteList.add(b);
  13.                             if (b == boundaryByte) {
  14.                                 if (byte1 == (byte)0) {
  15.                                     byte1 = boundaryByte;
  16.                                 } else if (byte1 == (byte)10 && !twoInRow) {
  17.                                     twoInRow = true;
  18.                                 } else if (byte1 == (byte)10 && twoInRow) {
  19.                                     channelThread.getBytes().add(byteList.toArray());
  20.                                     byte1 = (byte)0;
  21.                                     twoInRow = false;
  22.                                     byteList.clear();
  23.                                 }
  24.                             } else {
  25.                                 twoInRow = false;
  26.                                 byte1 = (byte)0;
  27.                             }
  28.                         }
  29.                         try {
  30.                             Thread.sleep(1);
  31.                         } catch (InterruptedException e) {
  32.                             e.printStackTrace();
  33.                         }
  34.                     }
  35.                 } catch (EOFException e) {
  36.                     System.out.println("Channel socket was closed!");
  37.                     closeConnection();
  38.                 } catch (SocketException e) {
  39.                     System.out.println("Channel socket was closed!");
  40.                     closeConnection();
  41.                 } catch (IOException e) {
  42.                     e.printStackTrace();
  43.                 }
  44.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement