X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Futil%2Fbinary%2FByteBufferReadable.java;h=c236604bad4c8e3d8a7ce36959d550a072ac0b15;hb=a7693ba6aaec35931c5448ef569046984e9f12f3;hp=455d337224452431899c84c958b8ff1ed4b10d35;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/ByteBufferReadable.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/ByteBufferReadable.java index 455d33722..c236604ba 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/ByteBufferReadable.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/ByteBufferReadable.java @@ -1,20 +1,20 @@ -/******************************************************************************* - * 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.IOException; -import java.nio.ByteBuffer; -import java.nio.ByteOrder; +import java.io.DataInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.ByteOrder; public class ByteBufferReadable implements BinaryReadable { @@ -36,53 +36,53 @@ public class ByteBufferReadable implements BinaryReadable { @Override public byte readByte() { return buf.get(); - } - - 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; - } + } + + 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 - public boolean readBoolean() throws IOException { - return buf.get()!=0; - } + @Override + public boolean readBoolean() throws IOException { + return buf.get()!=0; + } @Override public void readFully(byte[] dst, int offset, int length) { @@ -145,21 +145,21 @@ public class ByteBufferReadable implements BinaryReadable { @Override public short readShort() { return buf.getShort(); - } - - 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; - } + } + + 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() { @@ -191,15 +191,15 @@ public class ByteBufferReadable implements BinaryReadable { @Override public long skipBytes(long bytes) throws IOException { long newPosition = bytes + position(); - position( newPosition ); + position( newPosition ); + return bytes; + } + + @Override + public int skipBytes(int bytes) throws IOException { + long newPosition = bytes + position(); + position( newPosition ); return bytes; } - - @Override - public int skipBytes(int bytes) throws IOException { - long newPosition = bytes + position(); - position( newPosition ); - return bytes; - } }