jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r632252 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ data/ data/db/ fs/ fs/db/ fs/local/ journal/ persistence/bundle/ persistence/bundle/util/ persistence/db/ persistence/util/ query/lucene/ state/ value/
Date Fri, 29 Feb 2008 07:42:51 GMT
Author: jukka
Date: Thu Feb 28 23:42:44 2008
New Revision: 632252

URL: http://svn.apache.org/viewvc?rev=632252&view=rev
Log:
JCR-1395: Use Commons IO 1.4
    - Use IOUtils.closeQuietly to simplify code
    - Use IOUtils.copy to simplify code
    - Use FileUtils.copyFile to simplify code
    - Use DataInputStream.readFully to simplify code
    - Use DigestOutputStream to simplify code
    

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileRecordLog.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/FileSystemBLOBStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextExtractorJob.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/TransientRepository.java
Thu Feb 28 23:42:44 2008
@@ -33,6 +33,7 @@
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.api.JackrabbitRepository;
 import org.apache.jackrabbit.core.config.ConfigurationException;
 import org.apache.jackrabbit.core.config.RepositoryConfig;
@@ -220,13 +221,8 @@
                             InputStream input =
                                 TransientRepository.class.getResourceAsStream(
                                         DEFAULT_REPOSITORY_XML);
-                            byte[] buffer = new byte[BUFFER_SIZE];
                             try {
-                                int n = input.read(buffer);
-                                while (n != -1) {
-                                    output.write(buffer, 0, n);
-                                    n = input.read(buffer);
-                                }
+                                IOUtils.copy(input, output);
                             } finally {
                                input.close();
                             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataStore.java
Thu Feb 28 23:42:44 2008
@@ -22,6 +22,7 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.ref.WeakReference;
+import java.security.DigestOutputStream;
 import java.security.MessageDigest;
 import java.security.NoSuchAlgorithmException;
 import java.util.ArrayList;
@@ -31,6 +32,8 @@
 import java.util.Map;
 import java.util.WeakHashMap;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * Simple file-based data store. Data records are stored as normal files
  * named using a message digest of the contained binary stream.
@@ -166,14 +169,10 @@
             // stream length and the message digest of the stream
             long length = 0;
             MessageDigest digest = MessageDigest.getInstance(DIGEST);
-            OutputStream output = new FileOutputStream(temporary);
+            OutputStream output = new DigestOutputStream(
+                    new FileOutputStream(temporary), digest);
             try {
-                byte[] b = new byte[4096];
-                for (int n = input.read(b); n != -1; n = input.read(b)) {
-                    output.write(b, 0, n);
-                    digest.update(b, 0, n);
-                    length += n;
-                }
+                length = IOUtils.copyLarge(input, output);
             } finally {
                 output.close();
             }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/db/TempFileInputStream.java
Thu Feb 28 23:42:44 2008
@@ -25,6 +25,8 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.commons.io.IOUtils;
+
 /**
  * An input stream from a temp file that self-destructs when fully read or closed.
  */
@@ -43,14 +45,7 @@
      */
     public static long writeToFileAndClose(InputStream in, File file) throws IOException
{
         OutputStream out = new FileOutputStream(file);
-        byte[] b = new byte[4096];
-        while (true) {
-            int n = in.read(b);
-            if (n < 0) {
-                break;
-            }
-            out.write(b, 0, n);
-        }
+        IOUtils.copy(in, out);
         out.close();
         in.close();
         return file.length();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/FileSystemResource.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/FileSystemResource.java
Thu Feb 28 23:42:44 2008
@@ -161,11 +161,7 @@
     public void spool(OutputStream out) throws FileSystemException, IOException {
         InputStream in = fs.getInputStream(path);
         try {
-            byte[] buffer = new byte[8192];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                out.write(buffer, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
             IOUtils.closeQuietly(in);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/DatabaseFileSystem.java
Thu Feb 28 23:42:44 2008
@@ -826,11 +826,7 @@
                 InputStream in = getInputStream(filePath);
                 OutputStream out = new FileOutputStream(tmpFile);
                 try {
-                    int read;
-                    byte[] ba = new byte[8192];
-                    while ((read = in.read(ba, 0, ba.length)) != -1) {
-                        out.write(ba, 0, read);
-                    }
+                    IOUtils.copy(in, out);
                 } finally {
                     out.close();
                     in.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/db/OracleFileSystem.java
Thu Feb 28 23:42:44 2008
@@ -456,11 +456,7 @@
                 InputStream in = getInputStream(filePath);
                 OutputStream out = new FileOutputStream(tmpFile);
                 try {
-                    int read;
-                    byte[] ba = new byte[8192];
-                    while ((read = in.read(ba, 0, ba.length)) != -1) {
-                        out.write(ba, 0, read);
-                    }
+                    IOUtils.copy(in, out);
                 } finally {
                     out.close();
                     in.close();
@@ -576,11 +572,7 @@
                 blobClass.getMethod("getBinaryOutputStream", new Class[0]);
         OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null);
         try {
-            int read;
-            byte[] buf = new byte[8192];
-            while ((read = in.read(buf, 0, buf.length)) > -1) {
-                out.write(buf, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
             try {
                 out.flush();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/fs/local/FileUtil.java
Thu Feb 28 23:42:44 2008
@@ -17,10 +17,10 @@
 package org.apache.jackrabbit.core.fs.local;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
 import java.io.IOException;
 
+import org.apache.commons.io.FileUtils;
+
 /**
  * Static utility methods for recursively copying and deleting files and
  * directories.
@@ -74,17 +74,7 @@
                 throw new IOException("can't write to " + destParent.getPath());
             }
 
-            FileInputStream fis = new FileInputStream(src);
-            FileOutputStream fos = new FileOutputStream(dest);
-
-            byte[] buffer = new byte[8192];
-            int read = 0;
-            while ((read = fis.read(buffer)) > 0) {
-                fos.write(buffer, 0, read);
-            }
-
-            fis.close();
-            fos.close();
+            FileUtils.copyFile(src, dest);
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileRecordLog.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileRecordLog.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileRecordLog.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/journal/FileRecordLog.java
Thu Feb 28 23:42:44 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.journal;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.spi.commons.conversion.NamePathResolver;
 import org.apache.jackrabbit.spi.commons.namespace.NamespaceResolver;
 import org.slf4j.Logger;
@@ -256,12 +257,7 @@
             out.writeUTF(producerId);
             out.writeInt(length);
 
-            byte[] buffer = new byte[8192];
-            int len;
-
-            while ((len = in.read(buffer)) > 0) {
-                out.write(buffer, 0, len);
-            }
+            IOUtils.copy(in, out);
             out.flush();
 
             lastRevision +=

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/Oracle9PersistenceManager.java
Thu Feb 28 23:42:44 2008
@@ -18,6 +18,7 @@
 
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.persistence.PMContext;
 import org.apache.jackrabbit.core.persistence.bundle.util.NodePropBundle;
 import org.apache.jackrabbit.core.persistence.util.Serializer;
@@ -198,11 +199,7 @@
         Method getBinaryOutputStream = blobClass.getMethod("getBinaryOutputStream", new Class[0]);
         OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null);
         try {
-            int read;
-            byte[] buf = new byte[8192];
-            while ((read = in.read(buf, 0, buf.length)) > -1) {
-                out.write(buf, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
             try {
                 out.flush();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/BundleBinding.java
Thu Feb 28 23:42:44 2008
@@ -34,7 +34,6 @@
 
 import java.io.DataInputStream;
 import java.io.DataOutputStream;
-import java.io.EOFException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.HashSet;
@@ -369,10 +368,7 @@
                     // Strings are serialized as <length><byte[]>
                     int len = in.readInt();
                     byte[] bytes = new byte[len];
-                    int pos = 0;
-                    while (pos < len) {
-                        pos += in.read(bytes, pos, len - pos);
-                    }
+                    in.readFully(bytes);
                     val = InternalValue.valueOf(new String(bytes, "UTF-8"), type);
             }
             values[i] = val;
@@ -522,10 +518,7 @@
                     }
                     try {
                         byte[] bytes = new byte[len];
-                        int pos = 0;
-                        while (pos < len) {
-                            pos += in.read(bytes, pos, len - pos);
-                        }
+                        in.readFully(bytes);
                         log.info("  string: " + new String(bytes, "UTF-8"));
                     } catch (IOException e) {
                         log.error("Error while reading string value: " + e);
@@ -623,22 +616,12 @@
                         out.writeInt((int) size);
                         byte[] data = new byte[(int) size];
                         try {
-                            InputStream in = blobVal.getStream();
+                            DataInputStream in =
+                                new DataInputStream(blobVal.getStream());
                             try {
-                                int pos = 0;
-                                while (pos < size) {
-                                    int n = in.read(data, pos, (int) size - pos);
-                                    if (n < 0) {
-                                        throw new EOFException();
-                                    }
-                                    pos += n;
-                                }
+                                in.readFully(data);
                             } finally {
-                                try {
-                                    in.close();
-                                } catch (IOException e) {
-                                    // ignore
-                                }
+                                IOUtils.closeQuietly(in);
                             }
                         } catch (Exception e) {
                             String msg = "Error while storing blob. id="

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/bundle/util/ItemStateBinding.java
Thu Feb 28 23:42:44 2008
@@ -272,10 +272,7 @@
     public UUID readUUID(DataInputStream in) throws IOException {
         if (in.readBoolean()) {
             byte[] bytes = new byte[16];
-            int pos = 0;
-            while (pos < 16) {
-                pos += in.read(bytes, pos, 16 - pos);
-            }
+            in.readFully(bytes);
             return new UUID(bytes);
         } else {
             return null;

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/db/OraclePersistenceManager.java
Thu Feb 28 23:42:44 2008
@@ -378,11 +378,7 @@
                 blobClass.getMethod("getBinaryOutputStream", new Class[0]);
         OutputStream out = (OutputStream) getBinaryOutputStream.invoke(blob, null);
         try {
-            int read;
-            byte[] buf = new byte[8192];
-            while ((read = in.read(buf, 0, buf.length)) > -1) {
-                out.write(buf, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
             try {
                 out.flush();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/FileSystemBLOBStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/FileSystemBLOBStore.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/FileSystemBLOBStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/persistence/util/FileSystemBLOBStore.java
Thu Feb 28 23:42:44 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.persistence.util;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.fs.FileSystem;
 import org.apache.jackrabbit.core.fs.FileSystemPathUtil;
@@ -85,21 +86,14 @@
      * {@inheritDoc}
      */
     public void put(String blobId, InputStream in, long size) throws Exception {
-        OutputStream out = null;
         // the blobId is an absolute file system path
         FileSystemResource internalBlobFile = new FileSystemResource(fs, blobId);
         internalBlobFile.makeParentDirs();
+        OutputStream out = internalBlobFile.getOutputStream();
         try {
-            out = new BufferedOutputStream(internalBlobFile.getOutputStream());
-            byte[] buffer = new byte[8192];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                out.write(buffer, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
-            if (out != null) {
-                out.close();
-            }
+            out.close();
         }
     }
 

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextExtractorJob.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextExtractorJob.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextExtractorJob.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextExtractorJob.java
Thu Feb 28 23:42:44 2008
@@ -202,14 +202,10 @@
         }
 
         // spool into temp file
-        char[] buffer = new char[1024];
-        int len;
         InputStream in = null;
         try {
             try {
-                while ((len = r.read(buffer)) >= 0) {
-                    out.write(buffer, 0, len);
-                }
+                IOUtils.copy(r, out);
                 out.close();
             } finally {
                 r.close();

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/state/PropertyState.java
Thu Feb 28 23:42:44 2008
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.core.state;
 
+import org.apache.commons.io.IOUtils;
 import org.apache.jackrabbit.core.PropertyId;
 import org.apache.jackrabbit.core.NodeId;
 import org.apache.jackrabbit.core.ItemId;
@@ -272,14 +273,10 @@
                     if (type == PropertyType.BINARY) {
                         // special handling required for binary value
                         BLOBFileValue blob = val.getBLOBFileValue();
-                        InputStream in = blob.getStream();
                         out.writeLong(blob.getLength());
-                        byte[] buf = new byte[0x2000];
+                        InputStream in = blob.getStream();
                         try {
-                            int read;
-                            while ((read = in.read(buf)) > 0) {
-                                out.write(buf, 0, read);
-                            }
+                            IOUtils.copy(in, out);
                         } finally {
                             in.close();
                         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBFileValue.java
Thu Feb 28 23:42:44 2008
@@ -100,11 +100,7 @@
     public void spool(OutputStream out) throws RepositoryException, IOException {
         InputStream in = getStream();
         try {
-            byte[] buffer = new byte[0x2000];
-            int read;
-            while ((read = in.read(buffer)) > 0) {
-                out.write(buffer, 0, read);
-            }
+            IOUtils.copy(in, out);
         } finally {
             IOUtils.closeQuietly(in);
         }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java?rev=632252&r1=632251&r2=632252&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
Thu Feb 28 23:42:44 2008
@@ -57,15 +57,7 @@
             TransientFileFactory fileFactory = TransientFileFactory.getInstance();
             file = fileFactory.createTransientFile("bin", null, null);
             out = new FileOutputStream(file);
-            byte[] buffer = new byte[4 * 1024];
-            while (true) {
-                int len = in.read(buffer);
-                if (len < 0) {
-                    break;
-                }
-                out.write(buffer, 0, len);
-                length += len;
-            }
+            length = IOUtils.copyLarge(in, out);
         } catch (IOException e) {
             throw new RepositoryException("Error creating temporary file", e);
         } finally {



Mime
View raw message