KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > driver > EncodingScenario


1 /**
2  * C-JDBC: Clustered JDBC.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Nicolas Modrzyk
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1.driver;
26
27 import org.objectweb.cjdbc.common.sql.filters.AbstractBlobFilter;
28 import org.objectweb.cjdbc.common.sql.filters.HexaBlobFilter;
29 import org.objectweb.cjdbc.common.stream.encoding.ZipEncoding;
30 import org.objectweb.cjdbc.scenario.templates.Template;
31
32 /**
33  * This class defines scenario to test encoding and decoding
34  *
35  * @author <a HREF="mailto:Nicolas.Modrzyk@inria.fr">Nicolas Modrzyk </a>
36  * @version 1.0
37  */

38 public class EncodingScenario extends Template
39 {
40
41   /**
42    * @see junit.framework.TestCase#setUp()
43    */

44   protected void setUp()
45   {
46   }
47
48   /**
49    * @see junit.framework.TestCase#tearDown()
50    */

51   protected void tearDown()
52   {
53
54   }
55   
56   /**
57    * Test ZipEncoding. Works but we cannot convert back and forth to string so
58    * we can't use this method
59    *
60    * @throws Exception if fails.
61    */

62   public void testZipEncoding() throws Exception JavaDoc
63   {
64     String JavaDoc ss = "This is a very long string, please do not cut me";
65     byte[] zip = ZipEncoding.encode(ss.getBytes());
66     System.out.println(new String JavaDoc(zip));
67     byte[] unzip = ZipEncoding.decode(zip);
68     System.out.println(new String JavaDoc(unzip));
69     assertTrue("Decompressed byte[] is not what expected",ss.equals(new String JavaDoc(unzip)));
70   }
71  
72
73   /**
74    * Compare between different encoding methods for blobs
75    *
76    * @throws Exception if fails
77    */

78   public void testCompareEncoding() throws Exception JavaDoc
79   {
80     AbstractBlobFilter filter1 = new HexaBlobFilter();
81     //AbstractBlobFilter filter2 = new Base64BlobFilter();
82
//AbstractBlobFilter filter3 = new ZipBlobFilter();
83
String JavaDoc ss = "This is a very long string, please do not cut me";
84     
85     String JavaDoc ss1 = filter1.encode(ss);
86     System.out.println(ss1);
87     //String ss2 = filter2.encode(ss);
88
//System.out.println(ss2);
89
//String ss3 = filter3.encode(ss);
90
//System.out.println(ss3);
91

92     //assertTrue("Base64 encoding result is bigger than hexa encoding:[" + ss1
93
// + "][" + ss2 + "]", ss1.length() > ss2.length());
94
String JavaDoc test1 = new String JavaDoc(filter1.decode(ss1));
95     System.out.println(test1);
96     //String test2 = new String(filter2.decode(ss2));
97
//System.out.println(test2);
98
//String test3 = new String(filter3.decode(ss3));
99
//System.out.println(test3);
100

101     assertTrue("test1[" + test1 + "]!=original[" + ss + "]", test1
102         .equals(ss));
103     //assertTrue("test2[" + test2 + "]!=test3[" + test3 + "]", test2
104
// .equals(test3));
105
//assertTrue("test2[" + test2 + "]!=original[" + ss + "]", test2.equals(ss));
106
}
107
108 }
109
Popular Tags