KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > db4o > test > ExternalBlobs


1 /* Copyright (C) 2004 - 2006 db4objects Inc. http://www.db4o.com
2
3 This file is part of the db4o open source object database.
4
5 db4o is free software; you can redistribute it and/or modify it under
6 the terms of version 2 of the GNU General Public License as published
7 by the Free Software Foundation and as clarified by db4objects' GPL
8 interpretation policy, available at
9 http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
10 Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
11 Suite 350, San Mateo, CA 94403, USA.
12
13 db4o is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License along
19 with this program; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */

21 package com.db4o.test;
22
23 import java.io.*;
24
25 import com.db4o.*;
26 import com.db4o.ext.*;
27 import com.db4o.types.*;
28
29 public class ExternalBlobs {
30     
31     static final String JavaDoc BLOB_FILE_IN = Test.BLOB_PATH + "/regressionBlobIn.txt";
32     static final String JavaDoc BLOB_FILE_OUT = Test.BLOB_PATH + "/regressionBlobOut.txt";
33     
34     public Blob blob;
35     
36     void configure(){
37         try{
38             Db4o.configure().setBlobPath(Test.BLOB_PATH);
39         }catch(Exception JavaDoc e){
40             e.printStackTrace();
41         }
42     }
43     
44     void storeOne(){
45     }
46     
47     public void testOne(){
48         
49         if(new File(Test.BLOB_PATH).exists()){
50             try{
51                 char[] chout = new char[]{'H', 'i', ' ', 'f','o', 'l', 'k','s'};
52                 new File(BLOB_FILE_IN).delete();
53                 new File(BLOB_FILE_OUT).delete();
54                 FileWriter fw = new FileWriter(BLOB_FILE_IN);
55                 fw.write(chout);
56                 fw.flush();
57                 fw.close();
58                 blob.readFrom(new File(BLOB_FILE_IN));
59                 double status = blob.getStatus();
60                 while(status > Status.COMPLETED){
61                     Thread.sleep(50);
62                     status = blob.getStatus();
63                 }
64                 
65                 blob.writeTo(new File(BLOB_FILE_OUT));
66                 status = blob.getStatus();
67                 while(status > Status.COMPLETED){
68                     Thread.sleep(50);
69                     status = blob.getStatus();
70                 }
71                 File resultingFile = new File(BLOB_FILE_OUT);
72                 Test.ensure(resultingFile.exists());
73                 if(resultingFile.exists()){
74                     FileReader fr = new FileReader(resultingFile);
75                     char[] chin = new char[chout.length];
76                     fr.read(chin);
77                     for (int i = 0; i < chin.length; i++) {
78                         Test.ensure(chout[i] == chin[i]);
79                     }
80                     fr.close();
81                 }
82             }catch(Exception JavaDoc e){
83                 Test.ensure(false);
84                 e.printStackTrace();
85             }
86         }
87         
88     }
89
90 }
91
Popular Tags