]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.acorn/src/org/simantics/acorn/lru/FileInfo.java
Acorn: Fix WriteRunnable.runReally() and other fixes
[simantics/platform.git] / bundles / org.simantics.acorn / src / org / simantics / acorn / lru / FileInfo.java
index 660f245013b36bcf9879d90ed4af69de4d20a7cf..116464727c55cceb44500b740880c9912d1ca373 100644 (file)
@@ -2,8 +2,9 @@ package org.simantics.acorn.lru;
 
 import java.nio.file.Path;
 
+import org.simantics.acorn.exception.AcornAccessVerificationException;
+import org.simantics.acorn.exception.IllegalAcornStateException;
 import org.simantics.db.Database.Session.ResourceSegment;
-import org.simantics.db.server.ProCoreException;
 import org.simantics.utils.datastructures.Pair;
 
 import gnu.trove.list.array.TByteArrayList;
@@ -13,38 +14,33 @@ public class FileInfo extends LRUObject<String, FileInfo> {
        private TByteArrayList bytes;
        
        // Stub
-       public FileInfo(LRU<String, FileInfo> LRU, Path readDir, String id, int offset, int length) {
+       public FileInfo(LRU<String, FileInfo> LRU, Path readDir, String id, int offset, int length) throws AcornAccessVerificationException {
                super(LRU, id, readDir, id.toString() + ".extFile", offset, length, false, false);
                LRU.map(this);
        }
        
        // New
-       public FileInfo(LRU<String, FileInfo> LRU, String id, int size) {
+       public FileInfo(LRU<String, FileInfo> LRU, String id, int size) throws AcornAccessVerificationException {
                super(LRU, id, LRU.getDirectory(), id.toString() + ".extFile", true, true);
                this.bytes = new TByteArrayList(size);
                LRU.insert(this, accessTime);
        }
 
-       public byte[] getResourceFile() {
+       public byte[] getResourceFile() throws AcornAccessVerificationException, IllegalAcornStateException {
                
                if(VERIFY) verifyAccess();
                
                makeResident();
                return bytes.toArray();
-
        }
        
        
-       public ResourceSegment getResourceSegment(final byte[] clusterUID,
-                       final int resourceIndex, final long segmentOffset, short segmentSize)
-                       throws ProCoreException {
+       public ResourceSegment getResourceSegment(final byte[] clusterUID, final int resourceIndex, final long segmentOffset, short segmentSize) throws AcornAccessVerificationException, IllegalAcornStateException {
 
                if(VERIFY) verifyAccess();
 
                makeResident();
-
                try {
-
                        int segSize = segmentSize;
                        if (segSize < 0)
                                segSize += 65536;
@@ -52,7 +48,6 @@ public class FileInfo extends LRUObject<String, FileInfo> {
                                segSize = Math.min(65535, bytes.size());
 
                        final long valueSize = bytes.size();
-
                        final byte[] segment = bytes.toArray((int) segmentOffset, segSize);
 
                        return new ResourceSegment() {
@@ -82,18 +77,12 @@ public class FileInfo extends LRUObject<String, FileInfo> {
                                        return clusterUID;
                                }
                        };
-
                } catch (Throwable t) {
-
-                       t.printStackTrace();
-
+                       throw new IllegalAcornStateException(t);
                }
-
-               throw new UnsupportedOperationException();
-
        }
        
-       public void updateData(byte[] newBytes, long offset, long pos, long size) {
+       public void updateData(byte[] newBytes, long offset, long pos, long size) throws AcornAccessVerificationException, IllegalAcornStateException {
 
                if(VERIFY) verifyAccess();
                makeResident();