[exo-jcr-commits] exo-jcr SVN: r1007 - in jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl: dataflow and 1 other directory.
do-not-reply at jboss.org
do-not-reply at jboss.org
Fri Dec 11 09:44:56 EST 2009
Author: tolusha
Date: 2009-12-11 09:44:56 -0500 (Fri, 11 Dec 2009)
New Revision: 1007
Modified:
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/BinaryValue.java
jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
Log:
EXOJCR-300: create editable copy
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/BinaryValue.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/BinaryValue.java 2009-12-11 14:21:29 UTC (rev 1006)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/core/value/BinaryValue.java 2009-12-11 14:44:56 UTC (rev 1007)
@@ -138,22 +138,13 @@
* */
public void update(InputStream stream, long length, long position) throws IOException, RepositoryException
{
- // if (changedData == null)
- // {
- // ValueData internalData = this.getInternalData();
- //
- // if (internalData instanceof TransientValueData)
- // {
- // changedData = ((TransientValueData)internalData).createEditableCopy();
- // }
- // else
- // {
- // changedData = ((PersistedValueData)internalData).createTransientCopy();
- // }
- // }
- //
- // this.changedData.update(stream, length, position);
- // this.changed = true;
+ if (changedData == null)
+ {
+ changedData = createEditableCopy(this.getInternalData());
+ }
+
+ this.changedData.update(stream, length, position);
+ this.changed = true;
}
/**
@@ -164,13 +155,13 @@
*/
public void setLength(long size) throws IOException, RepositoryException
{
- // if (changedData == null)
- // {
- // changedData = ((TransientValueData)this.getInternalData()).createEditableCopy();
- // }
- //
- // this.changedData.setLength(size);
- // this.changed = true;
+ if (changedData == null)
+ {
+ changedData = createEditableCopy(this.getInternalData());
+ }
+
+ this.changedData.setLength(size);
+ this.changed = true;
}
/**
@@ -212,11 +203,11 @@
}
catch (FileNotFoundException e)
{
- throw new RepositoryException("Create transient copy error. " + e, e);
+ throw new RepositoryException("Create editable copy error. " + e, e);
}
catch (IOException e)
{
- throw new RepositoryException("Create transient copy error. " + e, e);
+ throw new RepositoryException("Create editable copy error. " + e, e);
}
}
}
Modified: jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java
===================================================================
--- jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-11 14:21:29 UTC (rev 1006)
+++ jcr/branches/1.12.0-OPT/exo.jcr.component.core/src/main/java/org/exoplatform/services/jcr/impl/dataflow/EditableValueData.java 2009-12-11 14:44:56 UTC (rev 1007)
@@ -19,14 +19,17 @@
package org.exoplatform.services.jcr.impl.dataflow;
import org.exoplatform.services.jcr.impl.util.io.FileCleaner;
+import org.exoplatform.services.jcr.impl.util.io.SpoolFile;
import org.exoplatform.services.log.ExoLogger;
import org.exoplatform.services.log.Log;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.MappedByteBuffer;
@@ -120,29 +123,25 @@
this.maxIOBuffSize = calcMaxIOSize();
- File sf = null;
- FileChannel sch = null;
+ File sf = File.createTempFile("jcrvdedit", null, tempDirectory);
+ OutputStream sfout = new FileOutputStream(sf);
try
{
- sf = File.createTempFile("jcrvdedit", null, tempDirectory);
+ byte[] tmpBuff = new byte[2048];
+ int read = 0;
+ int len = 0;
- sch = new RandomAccessFile(sf, "rw").getChannel();
-
- FileChannel sourceCh = new FileInputStream(spoolFile).getChannel();
- try
+ while ((read = stream.read(tmpBuff)) >= 0)
{
- sch.transferFrom(sourceCh, 0, sourceCh.size());
+ sfout.write(tmpBuff, 0, read);
+ len += read;
}
- finally
- {
- sourceCh.close();
- }
}
catch (final IOException e)
{
try
{
- sch.close();
+ sfout.close();
sf.delete();
}
catch (Exception e1)
@@ -161,7 +160,7 @@
this.data = null;
this.spoolFile = sf;
- this.spoolChannel = sch;
+ this.spoolChannel = new RandomAccessFile(sf, "rw").getChannel();
this.spooled = true;
}
More information about the exo-jcr-commits
mailing list