001: /* Copyright (C) 2004 - 2007 db4objects Inc. http://www.db4o.com
002:
003: This file is part of the db4o open source object database.
004:
005: db4o is free software; you can redistribute it and/or modify it under
006: the terms of version 2 of the GNU General Public License as published
007: by the Free Software Foundation and as clarified by db4objects' GPL
008: interpretation policy, available at
009: http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010: Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011: Suite 350, San Mateo, CA 94403, USA.
012:
013: db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014: WARRANTY; without even the implied warranty of MERCHANTABILITY or
015: FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
016: for more details.
017:
018: You should have received a copy of the GNU General Public License along
019: with this program; if not, write to the Free Software Foundation, Inc.,
020: 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
021: package com.db4o.test.legacy;
022:
023: import java.io.*;
024:
025: import com.db4o.*;
026: import com.db4o.ext.*;
027: import com.db4o.test.*;
028: import com.db4o.types.*;
029:
030: import db4ounit.extensions.util.*;
031:
032: public class ExternalBlobs {
033:
034: static final String BLOB_FILE_IN = AllTestsConfAll.BLOB_PATH
035: + "/regressionBlobIn.txt";
036: static final String BLOB_FILE_OUT = AllTestsConfAll.BLOB_PATH
037: + "/regressionBlobOut.txt";
038:
039: public Blob blob;
040:
041: void configure() {
042: try {
043: Db4o.configure().setBlobPath(AllTestsConfAll.BLOB_PATH);
044: deleteFiles();
045: } catch (Exception e) {
046: e.printStackTrace();
047: }
048: }
049:
050: void storeOne() {
051: }
052:
053: public void testOne() {
054:
055: if (new File(AllTestsConfAll.BLOB_PATH).exists()) {
056: try {
057: char[] chout = new char[] { 'H', 'i', ' ', 'f', 'o',
058: 'l', 'k', 's' };
059: deleteFiles();
060: FileWriter fw = new FileWriter(BLOB_FILE_IN);
061: fw.write(chout);
062: fw.flush();
063: fw.close();
064: blob.readFrom(new File(BLOB_FILE_IN));
065: double status = blob.getStatus();
066: while (status > Status.COMPLETED) {
067: Thread.sleep(50);
068: status = blob.getStatus();
069: }
070:
071: blob.writeTo(new File(BLOB_FILE_OUT));
072: status = blob.getStatus();
073: while (status > Status.COMPLETED) {
074: Thread.sleep(50);
075: status = blob.getStatus();
076: }
077: File resultingFile = new File(BLOB_FILE_OUT);
078: Test.ensure(resultingFile.exists());
079: if (resultingFile.exists()) {
080: FileReader fr = new FileReader(resultingFile);
081: char[] chin = new char[chout.length];
082: fr.read(chin);
083: for (int i = 0; i < chin.length; i++) {
084: Test.ensure(chout[i] == chin[i]);
085: }
086: fr.close();
087: }
088: } catch (Exception e) {
089: Test.ensure(false);
090: e.printStackTrace();
091: }
092: }
093:
094: }
095:
096: private void deleteFiles() throws IOException {
097: IOUtil.deleteDir(AllTestsConfAll.BLOB_PATH);
098: }
099:
100: }
|