-/*******************************************************************************\r
- * Copyright (c) 2010 Association for Decentralized Information Management in\r
- * Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- * VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
+/*******************************************************************************
+ * Copyright (c) 2010 Association for Decentralized Information Management in
+ * Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
package org.simantics.databoard.util.binary;
-import java.io.DataInputStream;\r
-import java.io.IOException;\r
-import java.nio.ByteBuffer;\r
-import java.nio.ByteOrder;\r
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.ByteOrder;
public class ByteBufferReadable implements BinaryReadable {
@Override
public byte readByte() {
return buf.get();
- }\r
- \r
- int _read() {\r
- if (buf.position()>=buf.limit()) return -1;\r
- return buf.get() & 0xff;\r
- }\r
- \r
- public final String readLine() throws IOException {\r
- StringBuffer input = new StringBuffer();\r
- int c = -1;\r
- boolean eol = false;\r
-\r
- while (!eol) {\r
- switch (c = _read()) {\r
- case -1:\r
- case '\n':\r
- eol = true;\r
- break;\r
- case '\r':\r
- eol = true;\r
- long cur = position();\r
- if ((_read()) != '\n') {\r
- position(cur);\r
- }\r
- break;\r
- default:\r
- input.append((char)c);\r
- break;\r
- }\r
- }\r
-\r
- if ((c == -1) && (input.length() == 0)) {\r
- return null;\r
- }\r
- return input.toString();\r
- } \r
- \r
- \r
- @Override\r
- public int readUnsignedByte() throws IOException {\r
- return buf.get() & 0x000000ff;\r
- } \r
+ }
+
+ int _read() {
+ if (buf.position()>=buf.limit()) return -1;
+ return buf.get() & 0xff;
+ }
+
+ public final String readLine() throws IOException {
+ StringBuffer input = new StringBuffer();
+ int c = -1;
+ boolean eol = false;
+
+ while (!eol) {
+ switch (c = _read()) {
+ case -1:
+ case '\n':
+ eol = true;
+ break;
+ case '\r':
+ eol = true;
+ long cur = position();
+ if ((_read()) != '\n') {
+ position(cur);
+ }
+ break;
+ default:
+ input.append((char)c);
+ break;
+ }
+ }
+
+ if ((c == -1) && (input.length() == 0)) {
+ return null;
+ }
+ return input.toString();
+ }
+
+
+ @Override
+ public int readUnsignedByte() throws IOException {
+ return buf.get() & 0x000000ff;
+ }
- @Override\r
- public boolean readBoolean() throws IOException {\r
- return buf.get()!=0;\r
- }\r
+ @Override
+ public boolean readBoolean() throws IOException {
+ return buf.get()!=0;
+ }
@Override
public void readFully(byte[] dst, int offset, int length) {
@Override
public short readShort() {
return buf.getShort();
- }\r
- \r
- public final String readUTF() throws IOException {\r
- return DataInputStream.readUTF(this);\r
- } \r
- \r
- @Override\r
- public char readChar() throws IOException {\r
- return buf.getChar();\r
- }
-\r
- @Override\r
- public int readUnsignedShort() {\r
- return buf.getShort() & 0xffff;\r
- }\r
+ }
+
+ public final String readUTF() throws IOException {
+ return DataInputStream.readUTF(this);
+ }
+
+ @Override
+ public char readChar() throws IOException {
+ return buf.getChar();
+ }
+
+ @Override
+ public int readUnsignedShort() {
+ return buf.getShort() & 0xffff;
+ }
@Override
public long length() {
@Override
public long skipBytes(long bytes) throws IOException {
long newPosition = bytes + position();
- position( newPosition );\r
+ position( newPosition );
+ return bytes;
+ }
+
+ @Override
+ public int skipBytes(int bytes) throws IOException {
+ long newPosition = bytes + position();
+ position( newPosition );
return bytes;
}
-\r
- @Override\r
- public int skipBytes(int bytes) throws IOException {\r
- long newPosition = bytes + position();\r
- position( newPosition );\r
- return bytes;\r
- }\r
}