1 /*******************************************************************************
2 * Copyright (c) 2010- Association for Decentralized Information Management in
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 *******************************************************************************/
12 package org.simantics.databoard.util.binary;
15 import java.io.IOException;
16 import java.io.RandomAccessFile;
17 import java.nio.ByteOrder;
18 import java.util.EnumSet;
21 * BinaryFile of multiple cache windows.
23 * @author Toni Kalajainen <toni.kalajainen@vtt.fi>
25 public class BinaryFile2 {
28 File, // The block represents the contents in file at file_pos
29 Memory, // Has allocated memory, and the data is in memory
30 Cache // The memory buffer reflects the contents in the file - it is cache
35 // Position in file, valid if File-flag is enabled
37 // Memory buffer, valid if Memory-flag is enabled
39 // Last read time of virtual time code
43 // Next block in a linked list
49 ByteOrder order = ByteOrder.BIG_ENDIAN;
54 public BinaryFile2(RandomAccessFile file, int buf_size) throws IOException
57 this.buf_size = buf_size;
60 public BinaryFile2(File file, int buf_size) throws IOException
62 this.raf = new RandomAccessFile(file, "rw");
64 this.buf_size = buf_size;
68 * Closes the object. Note, this will close the input random access file.
69 * This method may be called several times.
73 public synchronized void close() throws IOException {
74 if (raf==null) return;
86 public RandomAccessFile getRandomAccessFile() {
90 public ByteOrder order() {
94 public void order(ByteOrder order) {
95 if (order==null) throw new IllegalArgumentException("null argument");
100 * Complete flush. After this call all dirty blocks are flushed into disk.
101 * The sum of memory blocks will be less than buf_size.
103 * @throws IOException
105 public void flush() throws IOException {
108 // Prune until memory blocks use less memory than buf_size