abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From calav...@apache.org
Subject svn commit: r680979 - in /incubator/abdera/java/trunk/client: ./ src/main/java/org/apache/abdera/protocol/client/ src/main/java/org/apache/abdera/protocol/client/util/ src/test/java/org/apache/abdera/test/client/util/
Date Wed, 30 Jul 2008 11:21:00 GMT
Author: calavera
Date: Wed Jul 30 04:20:58 2008
New Revision: 680979

URL: http://svn.apache.org/viewvc?rev=680979&view=rev
Log:
Base64 implementation changed from sun implementation to commons-codec implementation
MultimediaRelatedRequestEntity renamed to MultipartRelatedRequestEntity(more correct)

Added:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultipartRelatedRequestEntity.java
      - copied, changed from r680926, incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultimediaRelatedRequestEntity.java
Removed:
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultimediaRelatedRequestEntity.java
Modified:
    incubator/abdera/java/trunk/client/pom.xml
    incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
    incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/util/MultipartRelatedRequestEntityTest.java

Modified: incubator/abdera/java/trunk/client/pom.xml
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/pom.xml?rev=680979&r1=680978&r2=680979&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/pom.xml (original)
+++ incubator/abdera/java/trunk/client/pom.xml Wed Jul 30 04:20:58 2008
@@ -14,49 +14,53 @@
    See the License for the specific language governing permissions and
    limitations under the License.
 -->
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
-  <parent>
-    <groupId>org.apache.abdera</groupId>
-    <artifactId>abdera</artifactId>
-    <version>0.5.0-incubating-SNAPSHOT</version>
-  </parent>  
-  <modelVersion>4.0.0</modelVersion>
-  <artifactId>abdera-client</artifactId>
-  <packaging>jar</packaging>
-  <name>Abdera Client</name>
-  <version>0.5.0-incubating-SNAPSHOT</version>
-  <description>Atom Publishing Protocol Client Implementation</description>
-
-  <properties>
-    <topDir>${basedir}/..</topDir>
-  </properties>
-  
-  <dependencies>
-      <dependency>
-        <groupId>junit</groupId>
-        <artifactId>junit</artifactId>
-      </dependency>
-    <dependency>
-      <groupId>org.apache.abdera</groupId>
-      <artifactId>abdera-core</artifactId>
-      <version>0.5.0-incubating-SNAPSHOT</version>
-      <scope>compile</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.abdera</groupId>
-      <artifactId>abdera-parser</artifactId>
-      <version>0.5.0-incubating-SNAPSHOT</version>
-      <scope>compile</scope>
-    </dependency>    
-    <dependency>
-      <groupId>commons-httpclient</groupId>
-      <artifactId>commons-httpclient</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.mortbay.jetty</groupId>
-      <artifactId>jetty</artifactId>
-      <version>${jetty.version}</version>
-      <scope>test</scope>
-    </dependency>
-  </dependencies>
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+  <parent>
+    <groupId>org.apache.abdera</groupId>
+    <artifactId>abdera</artifactId>
+    <version>0.5.0-incubating-SNAPSHOT</version>
+  </parent>  
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>abdera-client</artifactId>
+  <packaging>jar</packaging>
+  <name>Abdera Client</name>
+  <version>0.5.0-incubating-SNAPSHOT</version>
+  <description>Atom Publishing Protocol Client Implementation</description>
+
+  <properties>
+    <topDir>${basedir}/..</topDir>
+  </properties>
+  
+  <dependencies>
+      <dependency>
+        <groupId>junit</groupId>
+        <artifactId>junit</artifactId>
+      </dependency>
+      <dependency>
+  		<groupId>commons-codec</groupId>
+  		<artifactId>commons-codec</artifactId>
+  	</dependency>
+    <dependency>
+      <groupId>org.apache.abdera</groupId>
+      <artifactId>abdera-core</artifactId>
+      <version>0.5.0-incubating-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.abdera</groupId>
+      <artifactId>abdera-parser</artifactId>
+      <version>0.5.0-incubating-SNAPSHOT</version>
+      <scope>compile</scope>
+    </dependency>    
+    <dependency>
+      <groupId>commons-httpclient</groupId>
+      <artifactId>commons-httpclient</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.mortbay.jetty</groupId>
+      <artifactId>jetty</artifactId>
+      <version>${jetty.version}</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
 </project>
\ No newline at end of file

Modified: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java?rev=680979&r1=680978&r2=680979&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/AbderaClient.java
Wed Jul 30 04:20:58 2008
@@ -43,7 +43,7 @@
 import org.apache.abdera.protocol.client.util.BaseRequestEntity;
 import org.apache.abdera.protocol.client.util.EntityProviderRequestEntity;
 import org.apache.abdera.protocol.client.util.MethodHelper;
-import org.apache.abdera.protocol.client.util.MultimediaRelatedRequestEntity;
+import org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity;
 import org.apache.abdera.protocol.client.util.SimpleSSLProtocolSocketFactory;
 import org.apache.abdera.protocol.error.Error;
 import org.apache.abdera.protocol.error.ProtocolException;
@@ -277,7 +277,7 @@
    * @param options The request options
    */
   public ClientResponse post(String uri, Entry entry, InputStream media, String contentType,
RequestOptions options) {
-	  return execute("POST", uri, new MultimediaRelatedRequestEntity(entry, media, contentType),
options);
+	  return execute("POST", uri, new MultipartRelatedRequestEntity(entry, media, contentType),
options);
   }
 
   /**

Copied: incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultipartRelatedRequestEntity.java
(from r680926, incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultimediaRelatedRequestEntity.java)
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultipartRelatedRequestEntity.java?p2=incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultipartRelatedRequestEntity.java&p1=incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultimediaRelatedRequestEntity.java&r1=680926&r2=680979&rev=680979&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultimediaRelatedRequestEntity.java
(original)
+++ incubator/abdera/java/trunk/client/src/main/java/org/apache/abdera/protocol/client/util/MultipartRelatedRequestEntity.java
Wed Jul 30 04:20:58 2008
@@ -17,6 +17,7 @@
 */
 package org.apache.abdera.protocol.client.util;
 
+import java.io.ByteArrayOutputStream;
 import java.io.DataOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
@@ -24,11 +25,10 @@
 
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.httpclient.methods.RequestEntity;
 
-import sun.misc.BASE64Encoder;
-
-public class MultimediaRelatedRequestEntity implements RequestEntity {
+public class MultipartRelatedRequestEntity implements RequestEntity {
 
 	static final int BUFF_SIZE = 1024;
     static final byte[] buffer = new byte[BUFF_SIZE];
@@ -37,15 +37,15 @@
     private final String contentType;
 	private String boundary;
 	
-	public MultimediaRelatedRequestEntity(Entry entry, InputStream input) {
+	public MultipartRelatedRequestEntity(Entry entry, InputStream input) {
 		this(entry, input, null);
 	}	
 	
-	public MultimediaRelatedRequestEntity(Entry entry, InputStream input, String contentType)
{
+	public MultipartRelatedRequestEntity(Entry entry, InputStream input, String contentType)
{
 		this(entry, input, contentType, null);
 	}
 	
-	public MultimediaRelatedRequestEntity(Entry entry, InputStream input, String contentType,
String boundary) {		
+	public MultipartRelatedRequestEntity(Entry entry, InputStream input, String contentType,
String boundary) {		
 		this.input = input;		
 		this.entry = entry;
 		this.contentType = contentType != null?contentType:entry.getContentMimeType().toString()
;
@@ -77,10 +77,13 @@
 		}
 		out.writeBytes("content-id: <" + contentId.substring(4) + ">\r\n\r\n");
 		
-		int end;
-		while ((end = input.read(buffer)) != -1) {
-			out.writeBytes(new BASE64Encoder().encode(buffer));
-		}	
+		ByteArrayOutputStream output = new ByteArrayOutputStream();
+		while (input.read(buffer) != -1) {
+			output.write(buffer);
+		}		
+		
+		Base64 base64 = new Base64();
+	    out.write(base64.encode(output.toByteArray()));	
 		out.writeBytes("\r\n" + "--" + boundary + "--");
 	}
 

Modified: incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/util/MultipartRelatedRequestEntityTest.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/util/MultipartRelatedRequestEntityTest.java?rev=680979&r1=680978&r2=680979&view=diff
==============================================================================
--- incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/util/MultipartRelatedRequestEntityTest.java
(original)
+++ incubator/abdera/java/trunk/client/src/test/java/org/apache/abdera/test/client/util/MultipartRelatedRequestEntityTest.java
Wed Jul 30 04:20:58 2008
@@ -18,6 +18,7 @@
 package org.apache.abdera.test.client.util;
 
 import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
@@ -31,8 +32,9 @@
 import org.apache.abdera.i18n.iri.IRI;
 import org.apache.abdera.model.Entry;
 import org.apache.abdera.parser.stax.FOMEntry;
-import org.apache.abdera.protocol.client.util.MultimediaRelatedRequestEntity;
+import org.apache.abdera.protocol.client.util.MultipartRelatedRequestEntity;
 import org.apache.abdera.util.MimeTypeHelper;
+import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.httpclient.methods.RequestEntity;
 import org.junit.Test;
 import org.mortbay.io.WriterOutputStream;
@@ -50,7 +52,7 @@
 		entry.setId("tag:apache.org,2008:234534344");
 		entry.setSummary("multipart test");
 		entry.setContent(new IRI("cid:234234@example.com"), "image/jpg");
-		RequestEntity request = new MultimediaRelatedRequestEntity(entry, this.getClass().getResourceAsStream("info.png"),
+		RequestEntity request = new MultipartRelatedRequestEntity(entry, this.getClass().getResourceAsStream("info.png"),
 				"image/jpg", "asdfasdfasdf");
 		
 		StringWriter sw = new StringWriter();
@@ -77,18 +79,21 @@
 		int BUFF_SIZE = 1024;
 		
 		byte[] line = new byte[BUFF_SIZE];
-		int end;
-		String s = "";
-		while ((end = input.read(line)) != -1) {
-			s += new BASE64Encoder().encode(line);
+		ByteArrayOutputStream output = new ByteArrayOutputStream();
+		while (input.read(line) != -1) {
+			output.write(line);
 		}		
-	    		
-		ByteArrayInputStream bi = new ByteArrayInputStream(new BASE64Decoder().decodeBuffer(s));
+		
+		Base64 base64 = new Base64();
+	    byte[] encoded = base64.encode(output.toByteArray());
+		ByteArrayInputStream bi = new ByteArrayInputStream(base64.decode(encoded));
+		
 		File f = new File("info-out.png");
 		if (f.exists()) f.delete();
 		f.createNewFile();
 		FileOutputStream fo = new FileOutputStream(f);		
-				
+			
+		int end;
 		while ((end = bi.read(line)) != -1) {
 			fo.write(line, 0, end);
 		}



Mime
View raw message