You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by ju...@apache.org on 2014/02/28 20:35:25 UTC

svn commit: r1573041 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file: TarEntry.java TarFile.java

Author: jukka
Date: Fri Feb 28 19:35:24 2014
New Revision: 1573041

URL: http://svn.apache.org/r1573041
Log:
OAK-593: Segment-based MK

Extract tar entry location information to a separate class

Added:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java   (with props)
Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarFile.java

Added: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java?rev=1573041&view=auto
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java (added)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java Fri Feb 28 19:35:24 2014
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.jackrabbit.oak.plugins.segment.file;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+class TarEntry {
+
+    private final int offset;
+
+    private final int size;
+
+    TarEntry(int offset, int size) {
+        this.offset = offset;
+        this.size = size;
+    }
+
+    ByteBuffer read(FileAccess access) throws IOException {
+        return access.read(offset, size);
+    }
+
+}
\ No newline at end of file

Propchange: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarEntry.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarFile.java?rev=1573041&r1=1573040&r2=1573041&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarFile.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/file/TarFile.java Fri Feb 28 19:35:24 2014
@@ -34,19 +34,6 @@ class TarFile {
 
     private static final byte[] ZERO_BYTES = new byte[BLOCK_SIZE];
 
-    private static class Location {
-
-        int offset;
-
-        int size;
-
-        Location(int offset, int size) {
-            this.offset = offset;
-            this.size = size;
-        }
-
-    }
-
     private final File file;
 
     private final FileAccess access;
@@ -55,7 +42,7 @@ class TarFile {
 
     private final int maxFileSize;
 
-    private final Map<UUID, Location> entries = newConcurrentMap();
+    private final Map<UUID, TarEntry> entries = newConcurrentMap();
 
     TarFile(File file, int maxFileSize, boolean memoryMapping)
             throws IOException {
@@ -96,7 +83,7 @@ class TarFile {
 
             try {
                 UUID id = UUID.fromString(name);
-                entries.put(id, new Location(position + BLOCK_SIZE, size));
+                entries.put(id, new TarEntry(position + BLOCK_SIZE, size));
             } catch (IllegalArgumentException e) {
                 throw new IOException("Unexpected tar entry: " + name);
             }
@@ -110,9 +97,9 @@ class TarFile {
     }
 
     ByteBuffer readEntry(UUID id) throws IOException {
-        Location location = entries.get(id);
-        if (location != null) {
-            return access.read(location.offset, location.size);
+        TarEntry entry = entries.get(id);
+        if (entry != null) {
+            return entry.read(access);
         } else {
             return null;
         }
@@ -178,7 +165,7 @@ class TarFile {
         position += BLOCK_SIZE;
 
         access.write(position, b, offset, size);
-        entries.put(id, new Location(position, size));
+        entries.put(id, new TarEntry(position, size));
         position += size;
 
         int padding = BLOCK_SIZE - position % BLOCK_SIZE;