--- /dev/null
+/*******************************************************************************\r
+ * Copyright (c) 2010, 2016 Association for Decentralized Information Management\r
+ * in 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
+ * Semantum Oy - Implement java.io.Closeable\r
+ *******************************************************************************/\r
+package org.simantics.databoard.util.binary;
+
+import java.io.Closeable;\r
+import java.io.IOException;\r
+\r
+import org.simantics.databoard.file.RandomAccessBinaryList;\r
+
+/**
+ * Random access binary is a interface to access a binary object (BLOB).
+ * Binary object is random accessible and has a length.
+ * It can be read and written, enlarged and shrunk at any position.
+ * <p>
+ * There is a pointer which moves on every read and write operation. It can
+ * moved with {@link #position()}. If bytes are written and the pointer is
+ * moved outside the blob or moves while writing, the blob is enlarged.
+ *
+ * @see Blob Cascading implementation
+ * @see BinaryFile RandomAccessFile implementation
+ * @see RandomAccessBinaryList java.util.List implementation
+ * @author Toni Kalajainen
+ */
+public interface RandomAccessBinary extends Closeable, BinaryWriteable, BinaryReadable {
+
+ /**
+ * Flush write buffer
+ *
+ * @throws IOException
+ */
+ void flush() throws IOException;\r
+ \r
+ /**\r
+ * Reset internal cache. Before reseting unwritten changes are flushed to \r
+ * disc.\r
+ */\r
+ void reset() throws IOException;
+ \r
+ enum ByteSide { Left, Neither, Right }\r
+
+ /**
+ * Remove bytes from the position of the current pointer. If the pointer is
+ * outside the blob, an error is thrown.
+ *
+ * @param bytes\r
+ * @param side
+ * @throws IOException
+ */
+ void removeBytes(long bytes, ByteSide side) throws IOException;
+
+ /**
+ * Insert bytes at current pointer. If the pointer is outside the size of
+ * the blob, the blob is enlarged to fit the insertion.
+ *
+ * The operation does not move pointer.
+ *
+ * @param bytes\r
+ * @param side
+ * @throws IOException
+ */
+ void insertBytes(long bytes, ByteSide side) throws IOException;
+
+ /**
+ * Set length of the binary object.
+ *
+ * @param newLength
+ * @throws IOException
+ */
+ void setLength(long newLength) throws IOException;
+
+ /**
+ * Get the length of the binary object.
+ *
+ * @return the length
+ * @throws IOException
+ */
+ long length() throws IOException;
+
+ /**
+ * Flush and close the blob.
+ */
+ void close() throws IOException;
+\r
+ /**\r
+ * Check if binary is open.\r
+ * \r
+ * @return true if file is open\r
+ */\r
+ boolean isOpen();
+
+ /**
+ * Set new cursor position.
+ *
+ * The position can be set outside the binary object.
+ *
+ * @param newPosition
+ */
+ void position(long newPosition) throws IOException;
+
+ /**
+ * Get the position of the cursor
+ *
+ * @return cursor
+ */
+ long position() throws IOException;
+
+}
+