| 1 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 BLOB_FILE_IN = Test.BLOB_PATH + "/regressionBlobIn.txt"; 32 static final String 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 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 e){ 83 Test.ensure(false); 84 e.printStackTrace(); 85 } 86 } 87 88 } 89 90 } 91 | Popular Tags |