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.db4ounit.common.exceptions;
022:
023: import com.db4o.*;
024: import com.db4o.io.*;
025:
026: public class ExceptionIOAdapter extends IoAdapter {
027:
028: private IoAdapter _delegate = new RandomAccessFileAdapter();
029:
030: public static boolean exception = false;
031:
032: public ExceptionIOAdapter() {
033:
034: }
035:
036: protected ExceptionIOAdapter(String path, boolean lockFile,
037: long initialLength) throws Db4oIOException {
038: _delegate = _delegate
039: .open(path, lockFile, initialLength, false);
040: }
041:
042: public void close() throws Db4oIOException {
043: if (exception) {
044: throw new Db4oIOException();
045: } else {
046: _delegate.close();
047: }
048: }
049:
050: public void delete(String path) {
051: if (exception) {
052: return;
053: } else {
054: _delegate.delete(path);
055: }
056: }
057:
058: public boolean exists(String path) {
059: if (exception) {
060: return false;
061: } else {
062: return _delegate.exists(path);
063: }
064: }
065:
066: public long getLength() throws Db4oIOException {
067: if (exception) {
068: throw new Db4oIOException();
069: } else {
070: return _delegate.getLength();
071: }
072: }
073:
074: public IoAdapter open(String path, boolean lockFile,
075: long initialLength, boolean readOnly)
076: throws Db4oIOException {
077: return new ExceptionIOAdapter(path, lockFile, initialLength);
078: }
079:
080: public int read(byte[] bytes, int length) throws Db4oIOException {
081: if (exception) {
082: throw new Db4oIOException();
083: } else {
084: return _delegate.read(bytes, length);
085: }
086: }
087:
088: public void seek(long pos) throws Db4oIOException {
089: if (exception) {
090: throw new Db4oIOException();
091: } else {
092: _delegate.seek(pos);
093: }
094: }
095:
096: public void sync() throws Db4oIOException {
097: if (exception) {
098: throw new Db4oIOException();
099: } else {
100: _delegate.sync();
101: }
102: }
103:
104: public void write(byte[] buffer, int length) throws Db4oIOException {
105: if (exception) {
106: throw new Db4oIOException();
107: } else {
108: _delegate.write(buffer, length);
109: }
110: }
111:
112: }
|