diff options
author | Arne Schwabe <arne@rfc2549.org> | 2016-03-22 09:12:34 +0100 |
---|---|---|
committer | Arne Schwabe <arne@rfc2549.org> | 2016-03-22 09:12:45 +0100 |
commit | be658960e04d363b9551581dbf34b74f7e8472e4 (patch) | |
tree | af3ac8c394feadfc9e24b8acee563c0ced881c8f /main/src | |
parent | bf10e0bfa16050a7cd1347df6d531d12c1086ebb (diff) |
Use Bytebuffer to read/write length
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java index 9f63785c..2ba16d39 100644 --- a/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java +++ b/main/src/main/java/de/blinkt/openvpn/core/LogFileHandler.java @@ -18,6 +18,7 @@ import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.ByteBuffer; import java.util.Locale; import de.blinkt.openvpn.R; @@ -79,7 +80,6 @@ class LogFileHandler extends Handler { try { mBufLogfile.flush(); mLogFile.getChannel().truncate(0); - } catch (IOException e) { e.printStackTrace(); } @@ -93,8 +93,8 @@ class LogFileHandler extends Handler { // write binary format to disc byte[] liBytes = p.marshall(); - mLogFile.write(liBytes.length & 0xff); - mLogFile.write(liBytes.length >> 8); + byte[] lenBytes = ByteBuffer.allocate(4).putInt(liBytes.length).array(); + mLogFile.write(lenBytes); mLogFile.write(liBytes); p.recycle(); } @@ -119,13 +119,13 @@ class LogFileHandler extends Handler { BufferedInputStream logFile = new BufferedInputStream(new FileInputStream(logfile)); byte[] buf = new byte[8192]; - int read = logFile.read(buf, 0, 2); + int read = logFile.read(buf, 0, 4); int itemsRead=0; - while (read > 0) { - // Marshalled LogItem - int len = (0xff & buf[0]) | buf[1] << 8; + while (read >= 4) { + int len = ByteBuffer.wrap(buf, 0, 4).asIntBuffer().get(); + // Marshalled LogItem read = logFile.read(buf, 0, len); Parcel p = Parcel.obtain(); |