Skip to content
Browse files

Introducing DZUtil; moving ByteArrayAccess to DZUtil.

  • Loading branch information...
1 parent 75b1a84 commit 4f05c35ca419531883c2d196b7995b53b9018785 @eriksoe eriksoe committed Jun 22, 2011
View
38 src/main/java/com/trifork/deltazip/DZUtil.java
@@ -0,0 +1,38 @@
+package com.trifork.deltazip;
+
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.nio.ByteBuffer;
+import java.nio.channels.WritableByteChannel;
+import java.nio.channels.Channels;
+
+public abstract class DZUtil {
+ public static class ByteArrayAccess implements DeltaZip.Access {
+ final byte[] data;
+ public ByteArrayAccess(byte[] data) {this.data = data;}
+
+ public long getSize() {return data.length;}
+ public ByteBuffer pread(long pos, long len) {
+ System.err.println("DB| pread("+pos+","+len+") of "+data.length);
+ return ByteBuffer.wrap(data, (int)pos, (int)len).slice().asReadOnlyBuffer();
+ }
+
+ public byte[] applyAppendSpec(DeltaZip.AppendSpecification spec) {
+ try {
+ int length = (int) (spec.prefix_size + spec.new_tail.remaining());
+ ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
+ baos.write(data);
+ WritableByteChannel channel = Channels.newChannel(baos);
+ channel.write(spec.new_tail);
+ channel.close();
+ return baos.toByteArray();
+ } catch (IOException ioe) {throw new RuntimeException(ioe);}
+ }
+ }
+
+
+ public static class FileAccess {
+
+ }
+}
+
View
28 src/test/java/com/trifork/deltazip/DeltaZipTest.java
@@ -2,10 +2,8 @@
import java.nio.ByteBuffer;
import java.io.IOException;
-import java.io.ByteArrayOutputStream;
-import java.nio.channels.WritableByteChannel;
-import java.nio.channels.Channels;
import com.trifork.deltazip.DeltaZip.AppendSpecification;
+import com.trifork.deltazip.DZUtil.ByteArrayAccess;
import org.junit.Test;
import static junit.framework.Assert.*;
@@ -109,32 +107,8 @@ public void test_add_get_with(byte[] file0, ByteBuffer rev1, ByteBuffer rev2) th
} catch (Exception e) {}
}
-
//======================================================================
- public static class ByteArrayAccess implements DeltaZip.Access {
- final byte[] data;
- public ByteArrayAccess(byte[] data) {this.data = data;}
-
- public long getSize() {return data.length;}
- public ByteBuffer pread(long pos, long len) {
- System.err.println("DB| pread("+pos+","+len+") of "+data.length);
- return ByteBuffer.wrap(data, (int)pos, (int)len).slice().asReadOnlyBuffer();
- }
-
- public byte[] applyAppendSpec(DeltaZip.AppendSpecification spec) {
- try {
- int length = (int) (spec.prefix_size + spec.new_tail.remaining());
- ByteArrayOutputStream baos = new ByteArrayOutputStream(length);
- baos.write(data);
- WritableByteChannel channel = Channels.newChannel(baos);
- channel.write(spec.new_tail);
- channel.close();
- return baos.toByteArray();
- } catch (IOException ioe) {throw new RuntimeException(ioe);}
- }
- }
-
public static String toString(ByteBuffer buf) {
int save_pos = buf.position();
String r = new String(DeltaZip.toByteArray(buf));

0 comments on commit 4f05c35

Please sign in to comment.
Something went wrong with that request. Please try again.