X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Futil%2Fbinary%2FBlob.java;h=cbd221ca59ef5775065b1b8ffe25fc2f768d044c;hb=77921feee3f8331ab54796ff0832921405bea874;hp=db5e20e8bdba0cbc40df049bb31a3d010f847602;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/Blob.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/Blob.java index db5e20e8b..cbd221ca5 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/Blob.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/Blob.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.util.WeakHashMap; +import java.io.DataInputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.WeakHashMap; /** * Blob is recursive random access binary. Blob is isolated @@ -53,7 +53,7 @@ public class Blob implements RandomAccessBinary { * @throws IOException */ public Blob(RandomAccessBinary parent) throws IOException { - this(parent, 0, parent.length()); + this(parent, 0, parent.length()); } /** @@ -63,7 +63,7 @@ public class Blob implements RandomAccessBinary { * @param start * @param length */ - public Blob(RandomAccessBinary parent, long start, long length) { + public Blob(RandomAccessBinary parent, long start, long length) { this.parent = parent; this.start = start; this.length = length; @@ -74,19 +74,19 @@ public class Blob implements RandomAccessBinary { if (children == null) children = new WeakHashMap(1); children.put(result, Blob.class); return result; - } - - public RandomAccessBinary getParent() { - return parent; + } + + public RandomAccessBinary getParent() { + return parent; + } + + @Override + public void close() throws IOException { } @Override - public void close() throws IOException { - } - - @Override - public boolean isOpen() { - return parent.isOpen(); + public boolean isOpen() { + return parent.isOpen(); } @Override @@ -136,8 +136,8 @@ public class Blob implements RandomAccessBinary { */ void childGrewBackend(Blob child, long pos, long bytes) { - length += bytes; - assert(bytes>=0); + length += bytes; + assert(bytes>=0); if (children != null) { for (Blob c : children.keySet()) { @@ -151,7 +151,7 @@ public class Blob implements RandomAccessBinary { } /** - * Parent of this blob grew itself in the back-end. + * Parent of this blob grew itself in the back-end. * * @param parent * @param pos position in this blob @@ -159,19 +159,19 @@ public class Blob implements RandomAccessBinary { */ void parentGrew(Blob parent, long pos, long bytes, ByteSide side) { - if (pos<0 || (pos==0 && side!=ByteSide.Right) ) { - start += bytes; - return; - } - if (pos>=length) { - return; - } - // Grow applies this blob - if ( - ( pos==0 && side==ByteSide.Right ) || - ( pos==length && side==ByteSide.Left ) || - ( pos>0 && pos=length) { + return; + } + // Grow applies this blob + if ( + ( pos==0 && side==ByteSide.Right ) || + ( pos==length && side==ByteSide.Left ) || + ( pos>0 && poslength) throw new IndexOutOfBoundsException(); - if (bytes==0) return; + if (bytes==0) return; if (bytes<0) throw new IllegalArgumentException("bytes must be positive value"); // Go to backend @@ -228,9 +228,9 @@ public class Blob implements RandomAccessBinary { * @param bytes */ void childShrankBackend(Blob child, long pos, long bytes) - { - length -= bytes; - assert(bytes>=0); + { + length -= bytes; + assert(bytes>=0); // update siblings if (children != null) { @@ -245,23 +245,23 @@ public class Blob implements RandomAccessBinary { } /** - * Parent of this blob shrank itself in the back-end. - * + * Parent of this blob shrank itself in the back-end. + * * @param parent * @param pos position in this blob * @param bytes */ void parentShrunk(Blob parent, long pos, long bytes) - { - if (pos<0) { - start -= bytes; - return; - } - if (pos>=length) { - return; - } - // Change applies this blob - length -= bytes; + { + if (pos<0) { + start -= bytes; + return; + } + if (pos>=length) { + return; + } + // Change applies this blob + length -= bytes; // Notify children if (children != null) @@ -308,12 +308,12 @@ public class Blob implements RandomAccessBinary { @Override public void flush() throws IOException { parent.flush(); - } - - @Override - public void reset() throws IOException { - parent.reset(); - length = parent.length(); + } + + @Override + public void reset() throws IOException { + parent.reset(); + length = parent.length(); } @Override @@ -322,22 +322,22 @@ public class Blob implements RandomAccessBinary { parent.position(start + pointer); parent.write(b); pointer += 1; - } - - @Override - public void writeByte(int b) throws IOException { - assertHasWritableBytes(1); - parent.position(start + pointer); - parent.write(b); - pointer += 1; - } - - @Override - public void writeBoolean(boolean v) throws IOException { - assertHasWritableBytes(1); - parent.position(start + pointer); - parent.write( (byte) (v ? 1 : 0)); - pointer += 1; + } + + @Override + public void writeByte(int b) throws IOException { + assertHasWritableBytes(1); + parent.position(start + pointer); + parent.write(b); + pointer += 1; + } + + @Override + public void writeBoolean(boolean v) throws IOException { + assertHasWritableBytes(1); + parent.position(start + pointer); + parent.write( (byte) (v ? 1 : 0)); + pointer += 1; } @Override @@ -411,44 +411,44 @@ public class Blob implements RandomAccessBinary { parent.position(start + pointer); parent.writeShort(value); pointer += 2; - } - - @Override - public void writeChar(int value) throws IOException { - assertHasWritableBytes(2); - parent.position(start + pointer); - parent.writeChar(value); - pointer += 2; - } - - @Override - public void writeBytes(String s) throws IOException { - int len = s.length(); - assertHasWritableBytes(len); - parent.position(start + pointer); - parent.writeBytes(s); - pointer += len; - } - - @Override - public void writeChars(String s) throws IOException { - int len = s.length(); - assertHasWritableBytes(len*2); - parent.position(start + pointer); - parent.writeChars(s); - pointer += len*2; - } - - @Override - public void writeUTF(String s) throws IOException { - int len = UTF8.getModifiedUTF8EncodingByteLength(s); - assertHasWritableBytes(len+2); - parent.position(start + pointer); -// parent.writeUTF(s); - parent.writeShort(len); - UTF8.writeUTF(this, s); - pointer += len+2; - } + } + + @Override + public void writeChar(int value) throws IOException { + assertHasWritableBytes(2); + parent.position(start + pointer); + parent.writeChar(value); + pointer += 2; + } + + @Override + public void writeBytes(String s) throws IOException { + int len = s.length(); + assertHasWritableBytes(len); + parent.position(start + pointer); + parent.writeBytes(s); + pointer += len; + } + + @Override + public void writeChars(String s) throws IOException { + int len = s.length(); + assertHasWritableBytes(len*2); + parent.position(start + pointer); + parent.writeChars(s); + pointer += len*2; + } + + @Override + public void writeUTF(String s) throws IOException { + int len = UTF8.getModifiedUTF8EncodingByteLength(s); + assertHasWritableBytes(len+2); + parent.position(start + pointer); +// parent.writeUTF(s); + parent.writeShort(len); + UTF8.writeUTF(this, s); + pointer += len+2; + } @Override public byte readByte() throws IOException { @@ -457,24 +457,24 @@ public class Blob implements RandomAccessBinary { byte result = parent.readByte(); pointer += 1; return result; - } - - @Override - public int readUnsignedByte() throws IOException { - assertHasReadableBytes(1); - parent.position(start + pointer); - int result = parent.readUnsignedByte(); - pointer += 1; - return result; - } - - @Override - public boolean readBoolean() throws IOException { - assertHasReadableBytes(1); - parent.position(start + pointer); - boolean result = parent.readBoolean(); - pointer += 1; - return result; + } + + @Override + public int readUnsignedByte() throws IOException { + assertHasReadableBytes(1); + parent.position(start + pointer); + int result = parent.readUnsignedByte(); + pointer += 1; + return result; + } + + @Override + public boolean readBoolean() throws IOException { + assertHasReadableBytes(1); + parent.position(start + pointer); + boolean result = parent.readBoolean(); + pointer += 1; + return result; } @Override @@ -552,37 +552,37 @@ public class Blob implements RandomAccessBinary { short result = parent.readShort(); pointer += 2; return result; - } - - @Override - public String readLine() throws IOException { - assertHasReadableBytes(2); - parent.position(start + pointer); - String result = parent.readLine(); - pointer += ( parent.position() - start - pointer ); - return result; - } - - public final String readUTF() throws IOException { - return DataInputStream.readUTF(this); - } - - @Override - public char readChar() throws IOException { - assertHasReadableBytes(2); - parent.position(start + pointer); - char result = parent.readChar(); - pointer += 2; - return result; - } - - @Override - public int readUnsignedShort() throws IOException { - assertHasReadableBytes(2); - parent.position(start + pointer); - int result = parent.readShort() & 0xffff; - pointer += 2; - return result; + } + + @Override + public String readLine() throws IOException { + assertHasReadableBytes(2); + parent.position(start + pointer); + String result = parent.readLine(); + pointer += ( parent.position() - start - pointer ); + return result; + } + + public final String readUTF() throws IOException { + return DataInputStream.readUTF(this); + } + + @Override + public char readChar() throws IOException { + assertHasReadableBytes(2); + parent.position(start + pointer); + char result = parent.readChar(); + pointer += 2; + return result; + } + + @Override + public int readUnsignedShort() throws IOException { + assertHasReadableBytes(2); + parent.position(start + pointer); + int result = parent.readShort() & 0xffff; + pointer += 2; + return result; } void assertHasReadableBytes(long count) { @@ -612,15 +612,15 @@ public class Blob implements RandomAccessBinary { @Override public long skipBytes(long bytes) throws IOException { - pointer += bytes; + pointer += bytes; return bytes; - } + } - @Override - public int skipBytes(int bytes) throws IOException { - pointer += bytes; - return bytes; - } + @Override + public int skipBytes(int bytes) throws IOException { + pointer += bytes; + return bytes; + } public long getStartPositionInSourceBinary() { return start; @@ -638,7 +638,7 @@ public class Blob implements RandomAccessBinary { } - public void setPositionInSource(long start, long length) { + public void setPositionInSource(long start, long length) { this.start = start; this.length = length; }