Permalink
Browse files

added support for compressed transfers.

  • Loading branch information...
1 parent f7d0b09 commit 823df57257a98886d0caf51ea5cf877d68b10ad4 Neil committed Aug 4, 2009
@@ -295,6 +295,18 @@ public class WalrusDataResponseType extends WalrusResponseType {
String contentDisposition;
}
+public class WalrusDataGetRequestType extends WalrusDataRequestType {
+ protected Channel channel;
+
+ public Channel getChannel() {
+ return channel;
+ }
+
+ public void setChannel(Channel channel) {
+ this.channel = channel;
+ }
+}
+
public class WalrusDataGetResponseType extends WalrusDataResponseType {
}
@@ -436,13 +448,12 @@ public class SetObjectAccessControlPolicyResponseType extends WalrusResponseType
String description;
}
-public class GetObjectType extends WalrusDataRequestType {
+public class GetObjectType extends WalrusDataGetRequestType {
Boolean getMetaData;
Boolean getData;
Boolean inlineData;
Boolean deleteAfterGet;
Boolean getTorrent;
- Channel channel;
def GetObjectType() {
}
@@ -453,18 +464,14 @@ public class GetObjectType extends WalrusDataRequestType {
this.getMetaData = getMetaData;
this.inlineData = inlineData;
}
-
- public Channel getChannel() {
- return channel;
- }
}
public class GetObjectResponseType extends WalrusDataGetResponseType {
Status status;
String base64Data;
}
-public class GetObjectExtendedType extends WalrusDataRequestType {
+public class GetObjectExtendedType extends WalrusDataGetRequestType {
Boolean getData;
Boolean getMetaData;
Boolean inlineData;
@@ -510,7 +517,7 @@ public class UpdateWalrusConfigurationType extends WalrusRequestType {
public class UpdateWalrusConfigurationResponseType extends WalrusResponseType {
}
-public class GetDecryptedImageType extends WalrusDataRequestType {
+public class GetDecryptedImageType extends WalrusDataGetRequestType {
}
public class GetDecryptedImageResponseType extends WalrusDataGetResponseType {
@@ -0,0 +1,51 @@
+package edu.ucsb.eucalyptus.cloud.ws;
+
+import java.io.ByteArrayOutputStream;
+import java.io.RandomAccessFile;
+import java.util.zip.GZIPOutputStream;
+
+import org.apache.log4j.Logger;
+import org.jboss.netty.buffer.ChannelBuffers;
+import org.jboss.netty.handler.stream.ChunkedInput;
+
+public class CompressedChunkedFile implements ChunkedInput {
+ private Logger LOG = Logger.getLogger( CompressedChunkedFile.class );
+ private RandomAccessFile file;
+ private long offset;
+ private final int CHUNK_SIZE = 8192;
+ private long fileLength;
+
+ public CompressedChunkedFile(RandomAccessFile file, long fileLength) {
+ this.file = file;
+ this.offset = 0;
+ this.fileLength = fileLength;
+ }
+
+ @Override
+ public void close() throws Exception {
+ file.close();
+ }
+
+ @Override
+ public boolean hasNextChunk() throws Exception {
+ return offset < fileLength && file.getChannel().isOpen();
+ }
+
+ @Override
+ public Object nextChunk() throws Exception {
+ long offset = this.offset;
+ if (offset >= fileLength) {
+ return null;
+ }
+ int chunkSize = (int) Math.min(CHUNK_SIZE, fileLength - offset);
+ byte[] chunk = new byte[chunkSize];
+ file.readFully(chunk);
+ this.offset = offset + chunkSize;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ GZIPOutputStream zip = new GZIPOutputStream(out);
+ zip.write(chunk);
+ zip.close();
+ return ChannelBuffers.wrappedBuffer(out.toByteArray());
+ }
+}
+
Oops, something went wrong.

0 comments on commit 823df57

Please sign in to comment.