-/*******************************************************************************\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.EOFException;\r
-import java.io.IOException;\r
-import java.io.InputStream;\r
-import java.nio.ByteBuffer;\r
-\r
-import org.simantics.databoard.util.StreamUtil;\r
+import java.io.DataInputStream;
+import java.io.EOFException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.ByteBuffer;
+
+import org.simantics.databoard.util.StreamUtil;
/**
* Input stream reader
public class InputStreamReadable implements BinaryReadable {
InputStream is;
- long limit, position;\r
- \r
- public static BinaryReadable readFully(InputStream is) throws IOException {\r
- byte[] data = StreamUtil.readFully(is);\r
- return new BinaryMemory( data );\r
+ long limit, position;
+
+ public static BinaryReadable readFully(InputStream is) throws IOException {
+ byte[] data = StreamUtil.readFully(is);
+ return new BinaryMemory( data );
}
public InputStreamReadable(InputStream is, long limit)
throw new EOFException();
position++;
return value & 0xff;
- }\r
- \r
- /**\r
- * Get next byte\r
- * @return 0..255 or -1 on end of file\r
- * @throws IOException\r
- */\r
- int _read()\r
- throws IOException\r
- {\r
- int value = is.read();\r
- if (value==-1) return -1;\r
- position++; \r
- return value & 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
+ }
+
+ /**
+ * Get next byte
+ * @return 0..255 or -1 on end of file
+ * @throws IOException
+ */
+ int _read()
+ throws IOException
+ {
+ int value = is.read();
+ if (value==-1) return -1;
+ position++;
+ return value & 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
throws IOException
{
return (byte) _get();
- }\r
- \r
- @Override\r
- public char readChar() throws IOException {\r
- return (char) ( (_get() << 8) | _get() ) ;\r
- }\r
- \r
- @Override\r
- public int readUnsignedByte() throws IOException {\r
- return _get() & 0x000000ff;\r
- } \r
-\r
- @Override\r
- public boolean readBoolean() \r
- throws IOException \r
- {\r
- return _get()!=0;\r
+ }
+
+ @Override
+ public char readChar() throws IOException {
+ return (char) ( (_get() << 8) | _get() ) ;
+ }
+
+ @Override
+ public int readUnsignedByte() throws IOException {
+ return _get() & 0x000000ff;
+ }
+
+ @Override
+ public boolean readBoolean()
+ throws IOException
+ {
+ return _get()!=0;
}
@Override
throws IOException
{
return Float.intBitsToFloat(readInt());
- }\r
- \r
- public final String readUTF() throws IOException {\r
- return DataInputStream.readUTF(this);\r
+ }
+
+ public final String readUTF() throws IOException {
+ return DataInputStream.readUTF(this);
}
@Override
{
return (short) ( (_get() << 8) | _get() ) ;
}
-\r
- @Override\r
- public int readUnsignedShort() \r
- throws IOException \r
- {\r
- return ( (_get() << 8) | _get() ) ;\r
- } \r
+
+ @Override
+ public int readUnsignedShort()
+ throws IOException
+ {
+ return ( (_get() << 8) | _get() ) ;
+ }
@Override
public long length()
@Override
public long skipBytes(long bytes) throws IOException {
- is.skip(bytes); \r
+ is.skip(bytes);
+ return bytes;
+ }
+
+ @Override
+ public int skipBytes(int bytes) throws IOException {
+ is.skip(bytes);
return bytes;
}
-\r
- @Override\r
- public int skipBytes(int bytes) throws IOException {\r
- is.skip(bytes); \r
- return bytes;\r
- }\r
}