1 /*******************************************************************************
2 * Copyright (c) 2010, 2016 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 * Semantum Oy - Implement java.io.Closeable
12 *******************************************************************************/
13 package org.simantics.databoard.util.binary;
15 import java.io.Closeable;
16 import java.io.IOException;
18 import org.simantics.databoard.file.RandomAccessBinaryList;
21 * Random access binary is a interface to access a binary object (BLOB).
22 * Binary object is random accessible and has a length.
23 * It can be read and written, enlarged and shrunk at any position.
25 * There is a pointer which moves on every read and write operation. It can
26 * moved with {@link #position()}. If bytes are written and the pointer is
27 * moved outside the blob or moves while writing, the blob is enlarged.
29 * @see Blob Cascading implementation
30 * @see BinaryFile RandomAccessFile implementation
31 * @see RandomAccessBinaryList java.util.List implementation
32 * @author Toni Kalajainen
34 public interface RandomAccessBinary extends Closeable, BinaryWriteable, BinaryReadable {
41 void flush() throws IOException;
44 * Reset internal cache. Before reseting unwritten changes are flushed to
47 void reset() throws IOException;
49 enum ByteSide { Left, Neither, Right }
52 * Remove bytes from the position of the current pointer. If the pointer is
53 * outside the blob, an error is thrown.
59 void removeBytes(long bytes, ByteSide side) throws IOException;
62 * Insert bytes at current pointer. If the pointer is outside the size of
63 * the blob, the blob is enlarged to fit the insertion.
65 * The operation does not move pointer.
71 void insertBytes(long bytes, ByteSide side) throws IOException;
74 * Set length of the binary object.
79 void setLength(long newLength) throws IOException;
82 * Get the length of the binary object.
87 long length() throws IOException;
90 * Flush and close the blob.
92 void close() throws IOException;
95 * Check if binary is open.
97 * @return true if file is open
102 * Set new cursor position.
104 * The position can be set outside the binary object.
108 void position(long newPosition) throws IOException;
111 * Get the position of the cursor
115 long position() throws IOException;