[Joafip-svn] SF.net SVN: joafip:[3085] trunk
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2012-05-12 00:19:40
|
Revision: 3085
http://joafip.svn.sourceforge.net/joafip/?rev=3085&view=rev
Author: luc_peuvrier
Date: 2012-05-12 00:19:32 +0000 (Sat, 12 May 2012)
Log Message:
-----------
file management optimization
Modified Paths:
--------------
trunk/joafip/src/main/java/net/sf/joafip/service/FilePersistencePropertiesReader.java
trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/in/XmlImporter.java
trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestExclusiveDataAccessSessionUsingProps.java
trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractTestStoreMemoryLeak.java
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStream.java
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamMapped.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileOutputStreamOnRandomFile.java
trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
Added Paths:
-----------
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWriteRead1Gbyte.java
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStream.java
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStreamNIO.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileInputStreamOnRandomFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/FileInputStreamNIO.java
Removed Paths:
-------------
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWrite1Gbyte.java
trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamNIO.java
Modified: trunk/joafip/src/main/java/net/sf/joafip/service/FilePersistencePropertiesReader.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/service/FilePersistencePropertiesReader.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip/src/main/java/net/sf/joafip/service/FilePersistencePropertiesReader.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -188,10 +188,8 @@
} else if ("mapped".equals(value)) {
fileAccessMode = EnumFileAccessMode.MAPPED_RANDOM_FILE_ACCESS;
} else {
- throw new FilePersistenceException(
- "bad value \""
- + value
- + "\",random, nio, mapped2Gb, or mapped expected");
+ throw new FilePersistenceException("bad value \""
+ + value + "\",random, nio, or mapped expected");
}
filePersistenceProperties.setFileAccessMode(fileAccessMode);
} else if (JOAFIP_PATH.equals(key)) {
Modified: trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/in/XmlImporter.java
===================================================================
--- trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/in/XmlImporter.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip/src/main/java/net/sf/joafip/store/service/export_import/in/XmlImporter.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -18,6 +18,7 @@
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Deque;
@@ -28,6 +29,7 @@
import javax.xml.parsers.SAXParserFactory;
import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.stream.FileInputStreamNIO;
import net.sf.joafip.store.service.IStore;
import org.xml.sax.Attributes;
@@ -89,8 +91,9 @@
final XMLReader reader = saxParser.getXMLReader();
reader.setErrorHandler(new XmlReaderErrorHandler(this));
reader.setContentHandler(this);
- final String sourcePath = exportFile.toURI().toString();
- reader.parse(new InputSource(sourcePath));
+ // final String sourcePath = exportFile.toURI().toString();
+ final InputStream inputStream = new FileInputStreamNIO(exportFile);
+ reader.parse(new InputSource(inputStream));
} catch (SAXException exception) {
final String message = exception.getMessage();
final Exception embeddedException = exception.getException();
Modified: trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestExclusiveDataAccessSessionUsingProps.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestExclusiveDataAccessSessionUsingProps.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip/src/test/java/net/sf/joafip/service/rel300/TestExclusiveDataAccessSessionUsingProps.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -27,6 +27,7 @@
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
+import java.lang.reflect.Method;
import net.sf.joafip.AbstractDeleteFileTestCase;
import net.sf.joafip.NotStorableClass;
@@ -129,7 +130,7 @@
FilePersistenceDataCorruptedException, FileNotFoundException,
TestException {
initialize(new String[] {
- /**/"joafip.fileAccessMode=mapped2Gb",
+ /**/"joafip.fileAccessMode=mapped",
/**/"joafip.path=" + TestConstant.getWinRamDiskRuntimeDir(),
/**/"joafip.dataModelIdentifier=1",
/**/"joafip.proxyMode=enabled",
@@ -150,6 +151,9 @@
TestException {
initialize();
+ final Method method = Bob1.class.getDeclaredMethod(
+ "doSomethingOnOtherBob1Private", new Class<?>[] { Bob1.class });
+ filePersistence.addToNotCheckMethod(method);
dataAccessSession.open();
BobContainer bobContainer = initialBobContainer();
assertTrue("bobContainer be a proxy",
Modified: trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractTestStoreMemoryLeak.java
===================================================================
--- trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractTestStoreMemoryLeak.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip/src/test/java/net/sf/joafip/store/service/AbstractTestStoreMemoryLeak.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -9,11 +9,13 @@
import net.sf.joafip.NotStorableClass;
import net.sf.joafip.StorableAccess;
import net.sf.joafip.TestException;
+import net.sf.joafip.file.service.RandomAccessFileDirectMapped;
import net.sf.joafip.file.service.RandomAccessFileReadWriteCache;
import net.sf.joafip.java.util.PTreeSet;
import net.sf.joafip.meminspector.service.MemInspectorException;
import net.sf.joafip.meminspector.service.inspect.MemInspector;
import net.sf.joafip.store.entity.StoreHeader;
+import net.sf.joafip.store.service.bytecode.proxy.CheckMethodListener;
@NotStorableClass
@StorableAccess
@@ -62,6 +64,8 @@
memInspector.setMainPackageName("net.sf.joafip");
memInspector.addExcludedClass(StoreHeader.class);
memInspector.addDoNotInspectClass(RandomAccessFileReadWriteCache.class);
+ memInspector.addDoNotInspectClass(RandomAccessFileDirectMapped.class);
+ memInspector.addExcludedClass(CheckMethodListener.class);
helperMemoryUse.log("start");
PTreeSet<String> set = new PTreeSet<String>();
set.add("a");
@@ -84,9 +88,13 @@
helperMemoryUse.log("added " + i);
memInspector.inspect(store, true);
if (memInspector.added()) {
+ // PrintStream stream = new PrintStream("logs"// NOPMD
+ // + File.separator + "log_mem_start.txt");
stream = new PrintStream("logs"// NOPMD
+ File.separator + "log_mem_leak.txt");
memInspector.log(stream);
+ memInspector.serialize(new File("logs" + File.separator// NOPMD
+ + "log_mem_leak.bin"));
stream.close();
fail("object stay in memory iteration #" + i);
}
Deleted: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWrite1Gbyte.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWrite1Gbyte.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWrite1Gbyte.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -1,64 +0,0 @@
-/*
- * Copyright 2012 Luc Peuvrier
- * All rights reserved.
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * 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
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * 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.file.service;
-
-import java.io.OutputStream;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-public abstract class AbstractWrite1Gbyte {
-
- private static final byte[] DATA = new byte[1024];
-
- private final OutputStream outputStream;
-
- public AbstractWrite1Gbyte(final OutputStream outputStream) {
- super();
- this.outputStream = outputStream;
- }
-
- /**
- *
- * @return mS 1 giga byte write duration
- * @throws Exception
- * @throws IOException
- */
- protected long write() throws Exception {// NOPMD
- int count = -1;
- try {
- final long beginTime = System.currentTimeMillis();
- for (count = 0; count < 1024 * 1024; count++) {
- outputStream.write(DATA);
- }
- outputStream.close();
- return System.currentTimeMillis() - beginTime;
- } catch (Exception exception) {
- throw new Exception("count " + count + ", size "// NOPMD
- + (count * DATA.length), exception);
- }
- }
-}
Copied: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWriteRead1Gbyte.java (from rev 3083, trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWrite1Gbyte.java)
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWriteRead1Gbyte.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/AbstractWriteRead1Gbyte.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * 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
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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.file.service;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.util.Arrays;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public abstract class AbstractWriteRead1Gbyte {
+
+ private static final byte[] DATA = new byte[1024];
+
+ static {
+ for (int index = 0; index < 1024; index++) {
+ DATA[index] = (byte) index;
+ }
+ }
+
+ /**
+ *
+ * @return mS 1 giga byte write duration
+ * @throws Exception
+ * @throws IOException
+ */
+ protected long write(final OutputStream outputStream) throws Exception {// NOPMD
+ int count = -1;
+ try {
+ final long beginTime = System.currentTimeMillis();
+ for (count = 0; count < 1024 * 1024; count++) {
+ outputStream.write(DATA);
+ }
+ outputStream.close();
+ return System.currentTimeMillis() - beginTime;
+ } catch (Exception exception) {
+ throw new Exception("count " + count + ", size "// NOPMD
+ + (count * DATA.length), exception);
+ }
+ }
+
+ protected long read(final InputStream inputStream) throws Exception {// NOPMD
+ int count = -1;
+ try {
+ final byte[] data = new byte[1024];
+ final long beginTime = System.currentTimeMillis();
+ for (count = 0; count < 1024 * 1024; count++) {
+ final int read = inputStream.read(data);
+ if (read != 1024) {
+ throw new Exception("must read 1024 bytes");// NOPMD
+ }
+ if (!Arrays.equals(data, DATA)) {
+ throw new Exception("bad data");// NOPMD
+ }
+ }
+ final int read = inputStream.read(data);
+ if (read != -1) {
+ throw new Exception("must be end of file");// NOPMD
+ }
+ inputStream.close();
+ return System.currentTimeMillis() - beginTime;
+ } catch (Exception exception) {
+ throw new Exception("count " + count + ", size "// NOPMD
+ + (count * DATA.length), exception);
+ }
+ }
+}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStream.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStream.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStream.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -24,28 +24,33 @@
package net.sf.joafip.file.service;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileOutputStream;
+import java.io.InputStream;
import java.io.OutputStream;
+import net.sf.joafip.NotStorableClass;
+
/**
*
* @author luc peuvrier
*
*/
-public class MainWrite1GByteFileOutputStream extends AbstractWrite1Gbyte {
+@NotStorableClass
+public class MainWrite1GByteFileOutputStream extends AbstractWriteRead1Gbyte {
- public MainWrite1GByteFileOutputStream(final OutputStream outputStream) {
- super(outputStream);
- }
-
+ @SuppressWarnings("PMD")
public static void main(final String[] args) {
try {
final File file = new File("runtime/1gb.bin");
file.delete();
+ final MainWriteRead1GByteFileOutputStream main = new MainWriteRead1GByteFileOutputStream();
final OutputStream outputStream = new FileOutputStream(file);
- final MainWrite1GByteFileOutputStream main = new MainWrite1GByteFileOutputStream(
- outputStream);
- System.out.println("duration " + main.write() + " mS");// NOPMD
+ System.out.println("write duration " + main.write(outputStream)
+ + " mS");// NOPMD
+ final InputStream inputStream = new FileInputStream(file);
+ System.out.println("read duration " + main.read(inputStream)
+ + " mS");// NOPMD
} catch (Exception exception) {
exception.printStackTrace();// NOPMD
}
Modified: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamMapped.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamMapped.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamMapped.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -33,20 +33,18 @@
* @author luc peuvrier
*
*/
-public class MainWrite1GByteFileOutputStreamMapped extends AbstractWrite1Gbyte {
+public class MainWrite1GByteFileOutputStreamMapped extends
+ AbstractWriteRead1Gbyte {
- public MainWrite1GByteFileOutputStreamMapped(final OutputStream outputStream) {
- super(outputStream);
- }
-
+ @SuppressWarnings("PMD")
public static void main(final String[] args) {
try {
final File file = new File("runtime/1gb.bin");
file.delete();
+ final MainWrite1GByteFileOutputStreamMapped main = new MainWrite1GByteFileOutputStreamMapped();
final OutputStream outputStream = new FileOutputStreamMapped(file);
- final MainWrite1GByteFileOutputStreamMapped main = new MainWrite1GByteFileOutputStreamMapped(
- outputStream);
- System.out.println("duration " + main.write() + " mS");// NOPMD
+ System.out.println("write duration " + main.write(outputStream)
+ + " mS");// NOPMD
} catch (Exception exception) {
exception.printStackTrace();// NOPMD
}
Deleted: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamNIO.java
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamNIO.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamNIO.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -1,54 +0,0 @@
-/*
- * Copyright 2012 Luc Peuvrier
- * All rights reserved.
- *
- * This file is a part of JOAFIP.
- *
- * JOAFIP is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License.
- *
- * 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
- *
- * JOAFIP is distributed in the hope that it will be useful, but
- * 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.file.service;
-
-import java.io.File;
-import java.io.OutputStream;
-
-import net.sf.joafip.file.service.stream.FileOutputStreamNIO;
-
-/**
- *
- * @author luc peuvrier
- *
- */
-public class MainWrite1GByteFileOutputStreamNIO extends AbstractWrite1Gbyte {
-
- public MainWrite1GByteFileOutputStreamNIO(final OutputStream outputStream) {
- super(outputStream);
- }
-
- public static void main(final String[] args) {
- try {
- final File file = new File("runtime/1gb.bin");
- file.delete();
- final OutputStream outputStream = new FileOutputStreamNIO(file);
- final MainWrite1GByteFileOutputStreamNIO main = new MainWrite1GByteFileOutputStreamNIO(
- outputStream);
- System.out.println("duration " + main.write() + " mS");// NOPMD
- } catch (Exception exception) {
- exception.printStackTrace();// NOPMD
- }
- }
-}
Copied: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStream.java (from rev 3083, trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStream.java)
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStream.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStream.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * 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
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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.file.service;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import net.sf.joafip.NotStorableClass;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class MainWriteRead1GByteFileOutputStream extends
+ AbstractWriteRead1Gbyte {
+
+ @SuppressWarnings("PMD")
+ public static void main(final String[] args) {
+ try {
+ final File file = new File("runtime/1gb.bin");
+ file.delete();
+ final MainWriteRead1GByteFileOutputStream main = new MainWriteRead1GByteFileOutputStream();
+ final OutputStream outputStream = new FileOutputStream(file);
+ System.out.println("write duration " + main.write(outputStream)
+ + " mS");// NOPMD
+ final InputStream inputStream = new FileInputStream(file);
+ System.out.println("read duration " + main.read(inputStream)
+ + " mS");// NOPMD
+ } catch (Exception exception) {
+ exception.printStackTrace();// NOPMD
+ }
+ }
+}
Copied: trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStreamNIO.java (from rev 3083, trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWrite1GByteFileOutputStreamNIO.java)
===================================================================
--- trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStreamNIO.java (rev 0)
+++ trunk/joafip-4test/src/main/java/net/sf/joafip/file/service/MainWriteRead1GByteFileOutputStreamNIO.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -0,0 +1,57 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * 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
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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.file.service;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import net.sf.joafip.file.service.stream.FileOutputStreamNIO;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+public class MainWriteRead1GByteFileOutputStreamNIO extends
+ AbstractWriteRead1Gbyte {
+
+ @SuppressWarnings("PMD")
+ public static void main(final String[] args) {
+ try {
+ final File file = new File("runtime/1gb.bin");
+ file.delete();
+ final MainWriteRead1GByteFileOutputStreamNIO main = new MainWriteRead1GByteFileOutputStreamNIO();
+ final OutputStream outputStream = new FileOutputStreamNIO(file);
+ System.out.println("write duration " + main.write(outputStream)
+ + " mS");// NOPMD
+ final InputStream inputStream = new FileInputStream(file);
+ System.out.println("read duration " + main.read(inputStream)
+ + " mS");// NOPMD
+ } catch (Exception exception) {
+ exception.printStackTrace();// NOPMD
+ }
+ }
+}
Added: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileInputStreamOnRandomFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileInputStreamOnRandomFile.java (rev 0)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileInputStreamOnRandomFile.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * 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
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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.file.service.stream;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.FileIOException;
+import net.sf.joafip.file.service.IRandomAccessFile;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public abstract class AbstractFileInputStreamOnRandomFile extends InputStream {
+
+ private static final int BUFFER_SIZE = 1024 * 128;
+
+ private final byte[] buffer = new byte[BUFFER_SIZE];
+
+ private int bufferSize = 0;
+
+ private int inBufferIndex = 0;
+
+ private final IRandomAccessFile randomAccessFile;
+
+ public AbstractFileInputStreamOnRandomFile(
+ final IRandomAccessFile randomAccessFile) throws IOException {
+ super();
+ this.randomAccessFile = randomAccessFile;
+ try {
+ randomAccessFile.open();
+ } catch (FileIOException exception) {
+ throw new IOException(exception);
+ }
+ }
+
+ @Override
+ public void close() throws IOException {
+ try {
+ randomAccessFile.close();
+ } catch (FileIOException exception) {
+ throw new IOException(exception);
+ }
+ }
+
+ @Override
+ public int read() throws IOException {
+ if (inBufferIndex == bufferSize) {
+ try {
+ bufferSize = randomAccessFile.read(buffer, 0, BUFFER_SIZE);
+ } catch (FileIOException exception) {
+ throw new IOException(exception);
+ }
+ inBufferIndex = 0;
+ }
+ int read;
+ if (bufferSize == -1) {
+ read = -1;
+ } else {
+ read = buffer[inBufferIndex++] & 0xff;
+ }
+ return read;
+ }
+}
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileOutputStreamOnRandomFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileOutputStreamOnRandomFile.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/AbstractFileOutputStreamOnRandomFile.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -35,7 +35,7 @@
*
*/
@NotStorableClass
-public class AbstractFileOutputStreamOnRandomFile extends OutputStream {
+public abstract class AbstractFileOutputStreamOnRandomFile extends OutputStream {
private static final int BUFFER_SIZE = 1024 * 128;
Added: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/FileInputStreamNIO.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/FileInputStreamNIO.java (rev 0)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/stream/FileInputStreamNIO.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2012 Luc Peuvrier
+ * All rights reserved.
+ *
+ * This file is a part of JOAFIP.
+ *
+ * JOAFIP is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License.
+ *
+ * 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
+ *
+ * JOAFIP is distributed in the hope that it will be useful, but
+ * 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.file.service.stream;
+
+import java.io.File;
+import java.io.IOException;
+
+import net.sf.joafip.NotStorableClass;
+import net.sf.joafip.file.service.RandomAccessFileDirectNio;
+
+/**
+ *
+ * @author luc peuvrier
+ *
+ */
+@NotStorableClass
+public class FileInputStreamNIO extends AbstractFileInputStreamOnRandomFile {
+
+ public FileInputStreamNIO(final File file) throws IOException {
+ super(new RandomAccessFileDirectNio(file, 1, 0));
+ }
+
+ public FileInputStreamNIO(final String name) throws IOException {
+ this(name == null ? null : new File(name));
+ }
+}
Modified: trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java
===================================================================
--- trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java 2012-05-11 03:46:15 UTC (rev 3084)
+++ trunk/joafip-testsuite/src/main/java/net/sf/joafip/InErrorTests.java 2012-05-12 00:19:32 UTC (rev 3085)
@@ -24,10 +24,8 @@
import junit.framework.Test;
import junit.framework.TestSuite;
-import net.sf.joafip.btreeplus.service.TestBtreePlusDataManager;
-import net.sf.joafip.btreeplus.service.TestBtreePlusDataManagerBackup;
-import net.sf.joafip.btreeplus.service.TestBtreePlusDataMgrWithKey;
-import net.sf.joafip.btreeplus.service.TestBtreePlusDataMgrWithScenario;
+import net.sf.joafip.store.service.TestStoreMemoryLeakNoCacheGarbage;
+import net.sf.joafip.store.service.TestStoreMemoryLeakNoCacheNoGarbage;
/**
*
@@ -44,10 +42,8 @@
public static Test suite() {
final TestSuite suite = new TestSuite("in error Tests");
// $JUnit-BEGIN$
- suite.addTestSuite(TestBtreePlusDataManager.class);
- suite.addTestSuite(TestBtreePlusDataManagerBackup.class);
- suite.addTestSuite(TestBtreePlusDataMgrWithKey.class);
- suite.addTestSuite(TestBtreePlusDataMgrWithScenario.class);
+ suite.addTestSuite(TestStoreMemoryLeakNoCacheGarbage.class);
+ suite.addTestSuite(TestStoreMemoryLeakNoCacheNoGarbage.class);
// suite.addTest(xxxx.suite());
// $JUnit-END$
return suite;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|