X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.databoard%2Fsrc%2Forg%2Fsimantics%2Fdataboard%2Futil%2Fbinary%2FBinaryFile2.java;h=326b20252d0d08e13f84b25db82e74bf16ccd6d2;hb=refs%2Fchanges%2F21%2F4421%2F1;hp=f933bbd862f293cfb89f79c7ad8d7e2f5860ee75;hpb=969bd23cab98a79ca9101af33334000879fb60c5;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryFile2.java b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryFile2.java index f933bbd86..326b20252 100644 --- a/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryFile2.java +++ b/bundles/org.simantics.databoard/src/org/simantics/databoard/util/binary/BinaryFile2.java @@ -1,112 +1,112 @@ -/******************************************************************************* - * 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.File; -import java.io.IOException; -import java.io.RandomAccessFile; -import java.nio.ByteOrder; -import java.util.EnumSet; - -/** - * BinaryFile of multiple cache windows. - * - * @author Toni Kalajainen - */ -public class BinaryFile2 { - - static enum Flag { - File, // The block represents the contents in file at file_pos - Memory, // Has allocated memory, and the data is in memory - Cache // The memory buffer reflects the contents in the file - it is cache - } - static class Block { - // size of the block - int size; - // Position in file, valid if File-flag is enabled - long file_pos; - // Memory buffer, valid if Memory-flag is enabled - byte buf[]; - // Last read time of virtual time code - int access_time; - // Flags - EnumSet flags; - // Next block in a linked list - Block next; - } - - RandomAccessFile raf; - File file; - ByteOrder order = ByteOrder.BIG_ENDIAN; - Block first = null; - int buf_size; - long pointer = 0; - - public BinaryFile2(RandomAccessFile file, int buf_size) throws IOException - { - this.raf = file; - this.buf_size = buf_size; - } - - public BinaryFile2(File file, int buf_size) throws IOException - { - this.raf = new RandomAccessFile(file, "rw"); - this.file = file; - this.buf_size = buf_size; - } - - /** - * Closes the object. Note, this will close the input random access file. - * This method may be called several times. - * - * @throws IOException - */ - public synchronized void close() throws IOException { - if (raf==null) return; - flush(); - pointer = -1; - raf.close(); - raf = null; - first = null; - } - - public File file() { - return file; - } - - public RandomAccessFile getRandomAccessFile() { - return raf; - } - - public ByteOrder order() { - return order; - } - - public void order(ByteOrder order) { - if (order==null) throw new IllegalArgumentException("null argument"); - this.order = order; - } - - /** - * Complete flush. After this call all dirty blocks are flushed into disk. - * The sum of memory blocks will be less than buf_size. - * - * @throws IOException - */ - public void flush() throws IOException { - // Flush - - // Prune until memory blocks use less memory than buf_size - } - -} - +/******************************************************************************* + * 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.File; +import java.io.IOException; +import java.io.RandomAccessFile; +import java.nio.ByteOrder; +import java.util.EnumSet; + +/** + * BinaryFile of multiple cache windows. + * + * @author Toni Kalajainen + */ +public class BinaryFile2 { + + static enum Flag { + File, // The block represents the contents in file at file_pos + Memory, // Has allocated memory, and the data is in memory + Cache // The memory buffer reflects the contents in the file - it is cache + } + static class Block { + // size of the block + int size; + // Position in file, valid if File-flag is enabled + long file_pos; + // Memory buffer, valid if Memory-flag is enabled + byte buf[]; + // Last read time of virtual time code + int access_time; + // Flags + EnumSet flags; + // Next block in a linked list + Block next; + } + + RandomAccessFile raf; + File file; + ByteOrder order = ByteOrder.BIG_ENDIAN; + Block first = null; + int buf_size; + long pointer = 0; + + public BinaryFile2(RandomAccessFile file, int buf_size) throws IOException + { + this.raf = file; + this.buf_size = buf_size; + } + + public BinaryFile2(File file, int buf_size) throws IOException + { + this.raf = new RandomAccessFile(file, "rw"); + this.file = file; + this.buf_size = buf_size; + } + + /** + * Closes the object. Note, this will close the input random access file. + * This method may be called several times. + * + * @throws IOException + */ + public synchronized void close() throws IOException { + if (raf==null) return; + flush(); + pointer = -1; + raf.close(); + raf = null; + first = null; + } + + public File file() { + return file; + } + + public RandomAccessFile getRandomAccessFile() { + return raf; + } + + public ByteOrder order() { + return order; + } + + public void order(ByteOrder order) { + if (order==null) throw new IllegalArgumentException("null argument"); + this.order = order; + } + + /** + * Complete flush. After this call all dirty blocks are flushed into disk. + * The sum of memory blocks will be less than buf_size. + * + * @throws IOException + */ + public void flush() throws IOException { + // Flush + + // Prune until memory blocks use less memory than buf_size + } + +} +