X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Futil%2Fbinary%2FInputStreamReadable.java;h=f1f44d4b1cc2f5f52be516a4410c143012b72a6c;hb=refs%2Fchanges%2F22%2F2422%2F4;hp=17a34aca8fc3c96d57823c199844b01ef0c183d0;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/InputStreamReadable.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/InputStreamReadable.java index 17a34aca8..f1f44d4b1 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/InputStreamReadable.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/InputStreamReadable.java @@ -1,23 +1,23 @@ -/******************************************************************************* - * 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 - *******************************************************************************/ +/******************************************************************************* + * 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; -import java.io.EOFException; -import java.io.IOException; -import java.io.InputStream; -import java.nio.ByteBuffer; - -import org.simantics.databoard.util.StreamUtil; +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 @@ -27,11 +27,11 @@ import org.simantics.databoard.util.StreamUtil; public class InputStreamReadable implements BinaryReadable { InputStream is; - long limit, position; - - public static BinaryReadable readFully(InputStream is) throws IOException { - byte[] data = StreamUtil.readFully(is); - return new BinaryMemory( data ); + 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) @@ -53,51 +53,51 @@ public class InputStreamReadable implements BinaryReadable { throw new EOFException(); position++; return value & 0xff; - } - - /** - * 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(); - } + } + + /** + * 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 @@ -105,23 +105,23 @@ public class InputStreamReadable implements BinaryReadable { throws IOException { return (byte) _get(); - } - - @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 + 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 @@ -178,10 +178,10 @@ public class InputStreamReadable implements BinaryReadable { throws IOException { return Float.intBitsToFloat(readInt()); - } - - public final String readUTF() throws IOException { - return DataInputStream.readUTF(this); + } + + public final String readUTF() throws IOException { + return DataInputStream.readUTF(this); } @Override @@ -216,13 +216,13 @@ public class InputStreamReadable implements BinaryReadable { { return (short) ( (_get() << 8) | _get() ) ; } - - @Override - public int readUnsignedShort() - throws IOException - { - return ( (_get() << 8) | _get() ) ; - } + + @Override + public int readUnsignedShort() + throws IOException + { + return ( (_get() << 8) | _get() ) ; + } @Override public long length() @@ -238,15 +238,15 @@ public class InputStreamReadable implements BinaryReadable { @Override public long skipBytes(long bytes) throws IOException { - is.skip(bytes); + is.skip(bytes); + return bytes; + } + + @Override + public int skipBytes(int bytes) throws IOException { + is.skip(bytes); return bytes; } - - @Override - public int skipBytes(int bytes) throws IOException { - is.skip(bytes); - return bytes; - } }