[Joafip-svn] SF.net SVN: joafip:[2962] trunk/joafip-file/src/main/java/net/sf/joafip/ file/service
Brought to you by:
luc_peuvrier
|
From: <luc...@us...> - 2011-11-12 16:47:48
|
Revision: 2962
http://joafip.svn.sourceforge.net/joafip/?rev=2962&view=rev
Author: luc_peuvrier
Date: 2011-11-12 16:47:42 +0000 (Sat, 12 Nov 2011)
Log Message:
-----------
added write method (data offset length)
Modified Paths:
--------------
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java
trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java 2011-11-12 16:42:00 UTC (rev 2961)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/AbstractRandomAccessFile.java 2011-11-12 16:47:42 UTC (rev 2962)
@@ -145,6 +145,16 @@
throws FileIOException;
@Override
+ public void write(final byte[] data, final int offset, final int length)
+ throws FileIOException {
+ checkOpened();
+ writeImpl(data, offset, length);
+ }
+
+ protected abstract void writeImpl(byte[] data, int offset, int length)
+ throws FileIOException;
+
+ @Override
public long length() throws FileIOException {
checkOpened();
return lengthImpl();
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java 2011-11-12 16:42:00 UTC (rev 2961)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/IRandomAccessFile.java 2011-11-12 16:47:42 UTC (rev 2962)
@@ -75,6 +75,8 @@
void write(byte[] data, int length) throws FileIOException;
+ void write(byte[] data, int offset, int length) throws FileIOException;
+
long currentPositionInFile() throws FileIOException;
long length() throws FileIOException;
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2011-11-12 16:42:00 UTC (rev 2961)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirect.java 2011-11-12 16:47:42 UTC (rev 2962)
@@ -241,6 +241,18 @@
}
@Override
+ protected void writeImpl(final byte[] data,final int offset,final int length)
+ throws FileIOException {
+ try {
+ randomAccessFile.write(data, offset, length);
+ } catch (IOException exception) {
+ throw HELPER_FILE_UTIL.fileIOException("failed write in " + file,
+ file, exception);
+ }
+ currentPositionInFile += length;
+ }
+
+ @Override
public void clearCache() {
// nothing to do
}
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java 2011-11-12 16:42:00 UTC (rev 2961)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileDirectNio.java 2011-11-12 16:47:42 UTC (rev 2962)
@@ -290,6 +290,22 @@
}
@Override
+ protected void writeImpl(final byte[] data, final int offset,
+ final int length) throws FileIOException {
+ try {
+ final ByteBuffer byteBuffer = ByteBuffer.wrap(data, offset, length);
+ if (fileChannel.write(byteBuffer) != length) {
+ throw HELPER_FILE_UTIL.fileIOException("failed write " + length
+ + " bytes in " + file, file, null);
+ }
+ currentPositionInFile += length;
+ } catch (IOException exception) {
+ throw HELPER_FILE_UTIL.fileIOException("failed write in " + file,
+ file, exception);
+ }
+ }
+
+ @Override
public void clearCache() {
// nothing to do
}
Modified: trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java
===================================================================
--- trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2011-11-12 16:42:00 UTC (rev 2961)
+++ trunk/joafip-file/src/main/java/net/sf/joafip/file/service/RandomAccessFileReadWriteCache.java 2011-11-12 16:47:42 UTC (rev 2962)
@@ -269,12 +269,18 @@
@Override
public void writeImpl(final byte[] data) throws FileIOException {
- writeImpl(data, data.length);
+ writeImpl(data,0, data.length);
}
@Override
public void writeImpl(final byte[] data, final int length)
throws FileIOException {
+ writeImpl(data,0, length);
+ }
+
+ @Override
+ protected void writeImpl(final byte[] data,final int offset,final int length)
+ throws FileIOException {
int wrote = 0;
byte[] page;
do {
@@ -288,7 +294,7 @@
} else {
lengthToCopy = inPage;
}
- System.arraycopy(data, wrote, page, positionInPage, lengthToCopy);
+ System.arraycopy(data, offset+wrote, page, positionInPage, lengthToCopy);
wrote += lengthToCopy;
positionInFile += lengthToCopy;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|