[Joafip-svn] SF.net SVN: joafip:[3010] trunk/joafip-heapfile/src
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-04-17 04:52:13
|
Revision: 3010
http://joafip.svn.sourceforge.net/joafip/?rev=3010&view=rev
Author: luc_peuvrier
Date: 2012-04-17 04:52:03 +0000 (Tue, 17 Apr 2012)
Log Message:
-----------
useless abstract removed
Modified Paths:
--------------
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java
Added Paths:
-----------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
Removed Paths:
-------------
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java
trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -1,358 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.file.service.IRandomAccessFile;
-import net.sf.joafip.file.service.RandomAccessFileDirectNio;
-import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
-import net.sf.joafip.kvstore.service.HeapException;
-import net.sf.joafip.logger.JoafipLogger;
-
-/**
- * abstract file management
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public abstract class AbstractFileFor implements IFileForStorable {// NOPMD
- // abstract
- // class
- // without
- // abstract
- // method
-
- private static final String FILE_IS_OPENED = "file is opened";
-
- protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
-
- protected static final String FILE_ALREADY_CLOSED = "file already closed";
-
- protected static final String FILE_NOT_OPENNED = "file not opened";
-
- private static final String FILE_ALREADY_OPENED = "file already opened";
-
- protected static final String FAILED_DELETE_FILE = "failed delete file ";
-
- /** the file object for file heap */
- private final File file;
-
- /** for random read write file access */
- protected IRandomAccessFile randomAccessFile;
-
- /** true if file opened */
- private boolean opened = false;
-
- private Exception opennerTrace;
-
- private Exception closerTrace = new Exception("closer trace");
-
- /**
- * setup file to manage at construction, do not use cache<br>
- *
- * @param fileName
- * the file to manage name
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this(fileName == null ? null : new File(fileName), maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage at construction, do not use cache<br>
- *
- * @param file
- * the file to manage
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- this.file = file;
- randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param fileName
- * the file to manage name
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this(fileName == null ? null : new File(fileName), pageSize, maxPage,
- maxRetry, retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param file
- * the file to manage
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, maxRetry,
- retryMsDelay);
- }
-
- /**
- * setup file to manage and read/write cache at construction<br>
- *
- * @param file
- * the file to manage
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public AbstractFileFor(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- this.file = file;
- final RandomAccessFileDirectNio randomAccessFileDirect =
- /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
- randomAccessFile = new RandomAccessFileReadWriteCache(
- randomAccessFileDirect, pageSize, maxPage, haveReadCache);
- }
-
- @Override
- public void open() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
- } else {
- try {
- randomAccessFile.open();
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- opened = true;
- opennerTrace = new Exception("openner trace");
- }
- }
-
- @Override
- public void close() throws HeapException {
- if (opened) {
- opened = false;
- closerTrace = new Exception("closer trace");
- try {
- randomAccessFile.close();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- } else {
- throw new HeapException(FILE_ALREADY_CLOSED, closerTrace);
- }
- }
-
- @Override
- public void flush() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.flush();
- } catch (FileIOException e) {
- throw new HeapException(e);
- }
- }
-
- @Override
- public void resetFileSize() throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(0);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void deleteFileIfExists() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExists();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- @Override
- public void deleteFileIfExistsRenaming() throws HeapException {
- if (opened) {
- throw new HeapException(FILE_IS_OPENED);
- }
- if (logger.debugEnabled) {
- logger.debug("delete " + file);
- }
- try {
- randomAccessFile.deleteIfExistsRenaming();
- } catch (FileIOException exception) {
- throw new HeapException(FAILED_DELETE_FILE + file, exception);
- }
- }
-
- /**
- * @throws HeapException
- *
- */
- private void assertOpened() throws HeapException {
- if (!opened) {
- throw new HeapException(FILE_NOT_OPENNED, closerTrace);
- }
- }
-
- public boolean isOpened() {
- return opened;
- }
-
- @Override
- public void seek(final long positionInFile) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.seek(positionInFile);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public int read(final byte[] data) throws HeapException {
- assertOpened();
- try {
- return randomAccessFile.read(data);// NOPMD
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public void write(final byte[] data) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.write(data);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- @Override
- public File getFile() {
- return file;
- }
-
- @Override
- public long getFileSize() throws HeapException {
- long size;
- assertOpened();
- try {
- size = randomAccessFile.length();
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- return size;
- }
-
- /**
- * set the size of this file
- *
- * @param newSize
- * the file new size
- * @throws HeapException
- * if an I/O error occurs.
- */
- public void setFileSize(final long newSize) throws HeapException {
- assertOpened();
- try {
- randomAccessFile.setLength(newSize);
- } catch (FileIOException e) {
- throw closeAfterIOException(e);
- }
- }
-
- /**
- * close after io exception
- */
- protected HeapException closeAfterIOException(
- final FileIOException exception) throws HeapException {
- final HeapException fileForStorageException =
- /**/new HeapException(exception);
- try {
- close();
- } catch (HeapException exception2) {
- logger.warn("closing after exception", exception2);
- }
- return fileForStorageException;
- }
-
- public void copy(final String fileName) throws FileIOException {
- randomAccessFile.copy(fileName);
- }
-
- @Override
- public String toString() {
- final StringBuilder builder = new StringBuilder();
- builder.append("AbstractFileFor [file=");
- builder.append(file);
- builder.append(", opened=");
- builder.append(opened);
- builder.append("]");
- return builder.toString();
- }
-}
Deleted: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -1,158 +0,0 @@
-/*
- * Copyright 2007 Luc Peuvrier
- *
- * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
- * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.gnu.org/licenses/lgpl.html
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package net.sf.joafip.heapfile.service;
-
-import java.io.File;
-
-import net.sf.joafip.NotStorableClass;
-import net.sf.joafip.file.service.FileIOException;
-import net.sf.joafip.heapfile.entity.IFileStorable;
-import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
-import net.sf.joafip.kvstore.service.HeapException;
-
-/**
- * to read/write class implementing {@link IFileStorable} to/from file.<br>
- * {@link #open()} and {@link #close()}<br>
- *
- * @author luc peuvrier
- *
- */
-@NotStorableClass
-public class FileForStorable extends AbstractFileFor {
-
- /**
- * create a file to read from and write to {@link IFileStorable} object.<br>
- * no cache used for file management<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final String fileName, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- super(fileName, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * no cache used for file management<br>
- *
- * @param file
- * the file to use for object storing
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- * if an I/O error occurs while opening the file
- */
- public FileForStorable(final File file, final int maxRetry,
- final int retryMsDelay) throws HeapException {
- super(file, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- super(file, pageSize, maxPage, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param file
- * the file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param haveReadCache
- * true if have read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final File file, final int pageSize,
- final int maxPage, final boolean haveReadCache, final int maxRetry,
- final int retryMsDelay) {
- super(file, pageSize, maxPage, haveReadCache, maxRetry, retryMsDelay);
- }
-
- /**
- * create a file to read from and write to {@link IFileStorable} object<br>
- * file management use read/write cache<br>
- *
- * @param fileName
- * the file name of file to use for object storing
- * @param pageSize
- * page size ( number of byte ), must be greater or equals to
- * 1024
- * @param maxPage
- * maximum number of page for read cache
- * @param maxRetry
- * @param retryMsDelay
- * @throws HeapException
- */
- public FileForStorable(final String fileName, final int pageSize,
- final int maxPage, final int maxRetry, final int retryMsDelay)
- throws HeapException {
- super(fileName, pageSize, maxPage, maxRetry, retryMsDelay);
- }
-
- /**
- * copy this file to an other file
- *
- * @param fileForStorable
- * @throws HeapException
- */
- public void copy(final FileForStorable fileForStorable)
- throws HeapException {
- try {
- randomAccessFile.copy(fileForStorable.getFile().getAbsolutePath());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-
- @Override
- public void write(final ToBackupRecord toBackupRecord) throws HeapException {
- try {
- randomAccessFile.seek(toBackupRecord.getPositionInFile());
- randomAccessFile.write(toBackupRecord.getData());
- } catch (FileIOException exception) {
- throw new HeapException(exception);
- }
- }
-}
Copied: trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java (from rev 2999, trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/AbstractFileFor.java)
===================================================================
--- trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java (rev 0)
+++ trunk/joafip-heapfile/src/main/java/net/sf/joafip/heapfile/service/FileForStorable.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -0,0 +1,387 @@
+/*
+ * Copyright 2007 Luc Peuvrier
+ *
+ * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE
+ * Licensed under the LGPL License, Version 3, 29 June 2007 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.gnu.org/licenses/lgpl.html
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package net.sf.joafip.heapfile.service;
+
+import java.io.File;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.FileIOException;
+import net.sf.joafip.file.service.IRandomAccessFile;
+import net.sf.joafip.file.service.RandomAccessFileDirectNio;
+import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
+import net.sf.joafip.heapfile.entity.IFileStorable;
+import net.sf.joafip.heapfile.record.entity.ToBackupRecord;
+import net.sf.joafip.kvstore.service.HeapException;
+import net.sf.joafip.logger.JoafipLogger;
+
+/**
+ * to read/write class implementing {@link IFileStorable} to/from file.<br>
+ * {@link #open()} and {@link #close()}<br>
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class FileForStorable implements IFileForStorable {
+
+ private static final String FILE_IS_OPENED = "file is opened";
+
+ protected final JoafipLogger logger = JoafipLogger.getLogger(getClass());// NOPMD
+
+ protected static final String FILE_ALREADY_CLOSED = "file already closed";
+
+ protected static final String FILE_NOT_OPENNED = "file not opened";
+
+ private static final String FILE_ALREADY_OPENED = "file already opened";
+
+ protected static final String FAILED_DELETE_FILE = "failed delete file ";
+
+ /** the file object for file heap */
+ private final File file;
+
+ /** for random read write file access */
+ protected IRandomAccessFile randomAccessFile;
+
+ /** true if file opened */
+ private boolean opened = false;
+
+ private Exception opennerTrace;
+
+ private Exception closerTrace = new Exception("closer trace");
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object.<br>
+ * no cache used for file management<br>
+ *
+ * @param fileName
+ * the file name of file to use for storing storable object
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ * if an I/O error occurs while opening the file
+ */
+ public FileForStorable(final String fileName, final int maxRetry,
+ final int retryMsDelay) throws HeapException {
+ this(fileName == null ? null : new File(fileName), maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * no cache used for file management<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ * if an I/O error occurs while opening the file
+ */
+ public FileForStorable(final File file, final int maxRetry,
+ final int retryMsDelay) throws HeapException {
+ this.file = file;
+ randomAccessFile = new RandomAccessFileDirectNio(file, maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * file management use read/write cache<br>
+ *
+ * @param fileName
+ * the file name of file to use for object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final String fileName, final int pageSize,
+ final int maxPage, final int maxRetry, final int retryMsDelay)
+ throws HeapException {
+ this(fileName == null ? null : new File(fileName), pageSize, maxPage,
+ maxRetry, retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final File file, final int pageSize,
+ final int maxPage, final int maxRetry, final int retryMsDelay)
+ throws HeapException {
+ this.file = file;
+ final RandomAccessFileDirectNio randomAccessFileDirect =
+ /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
+ randomAccessFile = new RandomAccessFileReadWriteCache(
+ randomAccessFileDirect, pageSize, maxPage, maxRetry,
+ retryMsDelay);
+ }
+
+ /**
+ * create a file to read from and write to {@link IFileStorable} object<br>
+ * file management use read/write cache<br>
+ *
+ * @param file
+ * the file to use for storable object storing
+ * @param pageSize
+ * page size ( number of byte ), must be greater or equals to
+ * 1024
+ * @param maxPage
+ * maximum number of page for read cache
+ * @param haveReadCache
+ * true if have read cache
+ * @param maxRetry
+ * @param retryMsDelay
+ * @throws HeapException
+ */
+ public FileForStorable(final File file, final int pageSize,
+ final int maxPage, final boolean haveReadCache, final int maxRetry,
+ final int retryMsDelay) {
+ this.file = file;
+ final RandomAccessFileDirectNio randomAccessFileDirect =
+ /**/new RandomAccessFileDirectNio(file, maxRetry, retryMsDelay);
+ randomAccessFile = new RandomAccessFileReadWriteCache(
+ randomAccessFileDirect, pageSize, maxPage, haveReadCache);
+ }
+
+ @Override
+ public void open() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_ALREADY_OPENED, opennerTrace);
+ } else {
+ try {
+ randomAccessFile.open();
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ opened = true;
+ opennerTrace = new Exception("openner trace");
+ }
+ }
+
+ @Override
+ public void close() throws HeapException {
+ if (opened) {
+ opened = false;
+ closerTrace = new Exception("closer trace");
+ try {
+ randomAccessFile.close();
+ } catch (FileIOException e) {
+ throw new HeapException(e);
+ }
+ } else {
+ throw new HeapException(FILE_ALREADY_CLOSED, closerTrace);
+ }
+ }
+
+ @Override
+ public void flush() throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.flush();
+ } catch (FileIOException e) {
+ throw new HeapException(e);
+ }
+ }
+
+ @Override
+ public void resetFileSize() throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.setLength(0);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void deleteFileIfExists() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_IS_OPENED);
+ }
+ if (logger.debugEnabled) {
+ logger.debug("delete " + file);
+ }
+ try {
+ randomAccessFile.deleteIfExists();
+ } catch (FileIOException exception) {
+ throw new HeapException(FAILED_DELETE_FILE + file, exception);
+ }
+ }
+
+ @Override
+ public void deleteFileIfExistsRenaming() throws HeapException {
+ if (opened) {
+ throw new HeapException(FILE_IS_OPENED);
+ }
+ if (logger.debugEnabled) {
+ logger.debug("delete " + file);
+ }
+ try {
+ randomAccessFile.deleteIfExistsRenaming();
+ } catch (FileIOException exception) {
+ throw new HeapException(FAILED_DELETE_FILE + file, exception);
+ }
+ }
+
+ /**
+ * @throws HeapException
+ *
+ */
+ private void assertOpened() throws HeapException {
+ if (!opened) {
+ throw new HeapException(FILE_NOT_OPENNED, closerTrace);
+ }
+ }
+
+ public boolean isOpened() {
+ return opened;
+ }
+
+ @Override
+ public void seek(final long positionInFile) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.seek(positionInFile);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public int read(final byte[] data) throws HeapException {
+ assertOpened();
+ try {
+ return randomAccessFile.read(data);// NOPMD
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void write(final byte[] data) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.write(data);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ @Override
+ public void write(final ToBackupRecord toBackupRecord) throws HeapException {
+ try {
+ randomAccessFile.seek(toBackupRecord.getPositionInFile());
+ randomAccessFile.write(toBackupRecord.getData());
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ @Override
+ public File getFile() {
+ return file;
+ }
+
+ @Override
+ public long getFileSize() throws HeapException {
+ long size;
+ assertOpened();
+ try {
+ size = randomAccessFile.length();
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ return size;
+ }
+
+ /**
+ * set the size of this file
+ *
+ * @param newSize
+ * the file new size
+ * @throws HeapException
+ * if an I/O error occurs.
+ */
+ public void setFileSize(final long newSize) throws HeapException {
+ assertOpened();
+ try {
+ randomAccessFile.setLength(newSize);
+ } catch (FileIOException e) {
+ throw closeAfterIOException(e);
+ }
+ }
+
+ /**
+ * copy this file to an other file
+ *
+ * @param fileForStorable
+ * @throws HeapException
+ */
+ public void copy(final FileForStorable fileForStorable)
+ throws HeapException {
+ try {
+ randomAccessFile.copy(fileForStorable.getFile().getAbsolutePath());
+ } catch (FileIOException exception) {
+ throw new HeapException(exception);
+ }
+ }
+
+ /**
+ * close after io exception
+ */
+ protected HeapException closeAfterIOException(
+ final FileIOException exception) throws HeapException {
+ final HeapException fileForStorageException =
+ /**/new HeapException(exception);
+ try {
+ close();
+ } catch (HeapException exception2) {
+ logger.warn("closing after exception", exception2);
+ }
+ return fileForStorageException;
+ }
+
+ public void copy(final String fileName) throws FileIOException {
+ randomAccessFile.copy(fileName);
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder builder = new StringBuilder();
+ builder.append("AbstractFileFor [file=");
+ builder.append(file);
+ builder.append(", opened=");
+ builder.append(opened);
+ builder.append("]");
+ return builder.toString();
+ }
+}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/AbstractTestHeapDataManagerImpl.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -617,10 +617,10 @@
heapDataManager.flush();
identifier = heapDataManager.removeFirstDataRecord();
assertNotNull("must deleted first data record", identifier);
- assertEquals(BAD_VALUE,0L, identifier.value);
+ assertEquals(BAD_VALUE, 0L, identifier.value);
identifier = heapDataManager.removeFirstDataRecord();
assertNotNull("must deleted first data record", identifier);
- assertEquals(BAD_VALUE,1L, identifier.value);
+ assertEquals(BAD_VALUE, 1L, identifier.value);
assertNull(MUST_NOT_HAVE_DATA_RECORD,
heapDataManager.removeFirstDataRecord());
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/DualWrapDataManager.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -373,7 +373,8 @@
@Override
public void setDataRecordKeyComparator(
- final IDataRecordKeyManager dataRecordKeyComparator) throws HeapException {
+ final IDataRecordKeyManager dataRecordKeyComparator)
+ throws HeapException {
firstDataManager.setDataRecordKeyComparator(dataRecordKeyComparator);
secondDataManager.setDataRecordKeyComparator(dataRecordKeyComparator);
}
Modified: trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java
===================================================================
--- trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java 2012-04-16 03:07:06 UTC (rev 3009)
+++ trunk/joafip-heapfile/src/test/java/net/sf/joafip/heapfile/service/TestHeapFileDataMgrWithKey.java 2012-04-17 04:52:03 UTC (rev 3010)
@@ -58,7 +58,7 @@
assertTrue("must found 'A'", heapDataManager.hasDataRecord(keyA));
final byte[] readDataA = heapDataManager.readDataRecord(keyA);
assertNotNull("must read 'A' data", readDataA);
- assertEquals("bad value","valueA", new String(readDataA));
+ assertEquals("bad value", "valueA", new String(readDataA));
}
@Override
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|