jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r591286 - in /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core: ./ data/ query/lucene/ state/ value/
Date Fri, 02 Nov 2007 09:53:51 GMT
Author: thomasm
Date: Fri Nov  2 02:53:50 2007
New Revision: 591286

URL: http://svn.apache.org/viewvc?rev=591286&view=rev
Log:
JCR-1154: Throw DataStoreException instead of IOException

Added:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java
  (with props)
Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.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/query/lucene/TextFilterExtractor.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/BLOBInDataStore.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInTempFile.java
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/PropertyImpl.java
Fri Nov  2 02:53:50 2007
@@ -48,7 +48,6 @@
 import javax.jcr.nodetype.ConstraintViolationException;
 import javax.jcr.nodetype.PropertyDefinition;
 import javax.jcr.version.VersionException;
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Calendar;
@@ -739,20 +738,13 @@
             return;
         }
 
-        InternalValue value;
-        try {
-            value = InternalValue.createTemporary(stream, rep.getDataStore());
-            if (reqType != PropertyType.BINARY) {
-                // type conversion required
-                Value jcrValue = value.toJCRValue(session.getNamePathResolver());
-                Value targetVal = ValueHelper.convert(
-                        jcrValue, reqType, ValueFactoryImpl.getInstance());
-                value = InternalValue.create(targetVal, session.getNamePathResolver(), rep.getDataStore());
-            }
-        } catch (IOException ioe) {
-            String msg = "failed to spool stream to internal storage";
-            log.debug(msg);
-            throw new RepositoryException(msg, ioe);
+        InternalValue value = InternalValue.createTemporary(stream, rep.getDataStore());
+        if (reqType != PropertyType.BINARY) {
+            // type conversion required
+            Value jcrValue = value.toJCRValue(session.getNamePathResolver());
+            Value targetVal = ValueHelper.convert(
+                    jcrValue, reqType, ValueFactoryImpl.getInstance());
+            value = InternalValue.create(targetVal, session.getNamePathResolver(), rep.getDataStore());
         }
 
         internalSetValue(new InternalValue[]{value}, reqType);

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataRecord.java
Fri Nov  2 02:53:50 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.data;
 
-import java.io.IOException;
 import java.io.InputStream;
 
 /**
@@ -35,16 +34,16 @@
      * Returns the length of the binary stream in this record.
      *
      * @return length of the binary stream
-     * @throws IOException if the record could not be accessed
+     * @throws DataStoreException if the record could not be accessed
      */
-    long getLength() throws IOException;
+    long getLength() throws DataStoreException;
 
     /**
      * Returns the the binary stream in this record.
      *
      * @return binary stream
-     * @throws IOException if the record could not be accessed
+     * @throws DataStoreException if the record could not be accessed
      */
-    InputStream getStream() throws IOException;
+    InputStream getStream() throws DataStoreException;
 
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStore.java
Fri Nov  2 02:53:50 2007
@@ -16,7 +16,6 @@
  */
 package org.apache.jackrabbit.core.data;
 
-import java.io.IOException;
 import java.io.InputStream;
 import java.util.Iterator;
 
@@ -42,10 +41,10 @@
      *
      * @param identifier data identifier
      * @return identified data record
-     * @throws IOException if the data store could not be accessed,
+     * @throws DataStoreException if the data store could not be accessed,
      *                     or if the given identifier is invalid
      */
-    DataRecord getRecord(DataIdentifier identifier) throws IOException;
+    DataRecord getRecord(DataIdentifier identifier) throws DataStoreException;
 
     /**
      * Creates a new data record. The given binary stream is consumed and
@@ -67,9 +66,9 @@
      *
      * @param stream binary stream
      * @return data record that contains the given stream
-     * @throws IOException if the data store could not be accessed
+     * @throws DataStoreException if the data store could not be accessed
      */
-    DataRecord addRecord(InputStream stream) throws IOException;
+    DataRecord addRecord(InputStream stream) throws DataStoreException;
 
     /**
      * From now on, update the modified date of an object even when reading from it.

Added: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java?rev=591286&view=auto
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java
(added)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java
Fri Nov  2 02:53:50 2007
@@ -0,0 +1,46 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (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.apache.org/licenses/LICENSE-2.0
+ *
+ * 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 org.apache.jackrabbit.core.data;
+
+import javax.jcr.RepositoryException;
+
+/**
+ * Exception thrown by the Data Store module.
+ */
+public class DataStoreException extends RepositoryException {
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message.
+     *
+     * @param message the detailed message.
+     */
+    public DataStoreException(String message) {
+        super(message);
+    }
+
+    /**
+     * Constructs a new instance of this class with the specified detail
+     * message and root cause.
+     *
+     * @param message the detailed message.
+     * @param rootCause root failure cause
+     */
+    public DataStoreException(String message, Throwable cause) {
+        super(message, cause);
+    }
+}

Propchange: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/DataStoreException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/data/FileDataRecord.java
Fri Nov  2 02:53:50 2007
@@ -57,10 +57,14 @@
      * Returns an input stream for reading the file.
      *
      * @return file input stream
-     * @throws IOException if the file could not be opened
+     * @throws DataStoreException if the file could not be opened
      */
-    public InputStream getStream() throws IOException {
-        return new FileInputStream(file);
+    public InputStream getStream() throws DataStoreException {
+        try {
+            return new FileInputStream(file);
+        } catch (IOException e) {
+            throw new DataStoreException("Error opening input stream of " + file.getAbsolutePath(),
e);
+        }
     }
 
 }

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=591286&r1=591285&r2=591286&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
Fri Nov  2 02:53:50 2007
@@ -152,11 +152,12 @@
      *
      * @param input binary stream
      * @return data record that contains the given stream
-     * @throws IOException if the record could not be created
+     * @throws DataStoreException if the record could not be created
      */
-    public DataRecord addRecord(InputStream input) throws IOException {
-        File temporary = newTemporaryFile();
+    public DataRecord addRecord(InputStream input) throws DataStoreException {
+        File temporary = null;
         try {
+            temporary = newTemporaryFile();
             // Copy the stream to the temporary file and calculate the
             // stream length and the message digest of the stream
             long length = 0;
@@ -205,9 +206,13 @@
 
             return new FileDataRecord(identifier, file);
         } catch (NoSuchAlgorithmException e) {
-            throw new IOException(DIGEST + " not available: " + e.getMessage());
+            throw new DataStoreException(DIGEST + " not available", e);
+        } catch (IOException e) {
+            throw new DataStoreException("Could not add record", e);
         } finally {
-            temporary.delete();
+            if (temporary != null) {
+                temporary.delete();
+            }
         }
     }
 
@@ -241,8 +246,7 @@
         if (!directory.isDirectory()) {
             directory.mkdirs();
         }
-        File temporary = File.createTempFile(TMP, null, directory);
-        return temporary;
+        return File.createTempFile(TMP, null, directory);
     }
 
     /**

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/query/lucene/TextFilterExtractor.java
Fri Nov  2 02:53:50 2007
@@ -96,8 +96,10 @@
      */
     public Reader extractText(InputStream stream, String type, String encoding)
             throws IOException {
-        final InternalValue value = InternalValue.createTemporary(stream);
+        InternalValue v = null;
         try {
+            v = InternalValue.createTemporary(stream);
+            final InternalValue value = v;
             PropertyState state = new PropertyState(
                     (PropertyId) null, ItemState.STATUS_EXISTING, true);
             state.setValues(new InternalValue[] { value });
@@ -115,7 +117,9 @@
                 return new StringReader("");
             }
         } catch (RepositoryException e) {
-            value.getBLOBFileValue().discard();
+            if (v != null) {
+                v.getBLOBFileValue().discard();
+            }
             return new StringReader("");
         }
     }

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=591286&r1=591285&r2=591286&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
Fri Nov  2 02:53:50 2007
@@ -23,6 +23,8 @@
 import org.apache.jackrabbit.core.value.BLOBFileValue;
 import org.apache.jackrabbit.core.value.InternalValue;
 import org.apache.jackrabbit.spi.Name;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.jcr.PropertyType;
 import javax.jcr.RepositoryException;
@@ -35,6 +37,9 @@
  * <code>PropertyState</code> represents the state of a <code>Property</code>.
  */
 public class PropertyState extends ItemState {
+    
+    /** Logger instance */
+    private static Logger log = LoggerFactory.getLogger(PropertyState.class);
 
     /**
      * Serialization UID of this class.
@@ -305,51 +310,62 @@
                     final long length = in.readLong();
                     final InputStream stream = in;
                     // create InputStream wrapper of size 'length'
-                    values[i] = InternalValue.create(new InputStream() {
-
-                        private long consumed = 0;
-
-                        public int read() throws IOException {
-                            if (consumed >= length) {
-                                return -1;  // eof
-                            }
-                            int b = stream.read();
-                            consumed++;
-                            return b;
-                        }
-
-                        public int read(byte[] b, int off, int len) throws IOException {
-                            if (consumed >= length) {
-                                return -1;  // eof
-                            }
-                            if ((consumed + len) > length) {
-                                len = (int) (length - consumed);
-                            }
-                            int read = stream.read(b, off, len);
-                            consumed += read;
-                            return read;
-                        }
-
-                        public long skip(long n) throws IOException {
-                            if (consumed >= length && n > 0) {
-                                return -1;  // eof
-                            }
-                            if ((consumed + n) > length) {
-                                n = length - consumed;
-                            }
-                            long skipped = stream.skip(n);
-                            consumed += skipped;
-                            return skipped;
-                        }
-
-                        public void close() {
-                            // nop
-                        }
-                    });
+                    try {
+                        values[i] = createInternalValueFromInputStream(stream, length);
+                    } catch (RepositoryException e) {
+                        String msg = "Failed to create internal value: " + e.getMessage();
+                        log.error(msg, e);
+                        throw new IOException(msg);
+                    }
+                    
                 } else {
                     values[i] = InternalValue.valueOf(in.readUTF(), type);
                 }
             }
         }
+    }
+    
+    private InternalValue createInternalValueFromInputStream(final InputStream stream, final
long length) throws RepositoryException {
+        return InternalValue.create(new InputStream() {
+            
+            private long consumed = 0;
+
+            public int read() throws IOException {
+                if (consumed >= length) {
+                    return -1;  // eof
+                }
+                int b = stream.read();
+                consumed++;
+                return b;
+            }
+
+            public int read(byte[] b, int off, int len) throws IOException {
+                if (consumed >= length) {
+                    return -1;  // eof
+                }
+                if ((consumed + len) > length) {
+                    len = (int) (length - consumed);
+                }
+                int read = stream.read(b, off, len);
+                consumed += read;
+                return read;
+            }
+
+            public long skip(long n) throws IOException {
+                if (consumed >= length && n > 0) {
+                    return -1;  // eof
+                }
+                if ((consumed + n) > length) {
+                    n = length - consumed;
+                }
+                long skipped = stream.skip(n);
+                consumed += skipped;
+                return skipped;
+            }
+
+            public void close() {
+                // nop
+            }
+        });
     }
 }

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/BLOBInDataStore.java
Fri Nov  2 02:53:50 2007
@@ -19,10 +19,10 @@
 import org.apache.jackrabbit.core.data.DataIdentifier;
 import org.apache.jackrabbit.core.data.DataRecord;
 import org.apache.jackrabbit.core.data.DataStore;
+import org.apache.jackrabbit.core.data.DataStoreException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.io.IOException;
 import java.io.InputStream;
 
 import javax.jcr.RepositoryException;
@@ -83,18 +83,14 @@
     public long getLength() {
         try {
             return getDataRecord().getLength();
-        } catch (IOException e) {
+        } catch (DataStoreException e) {
             log.warn("getLength for " + identifier + " failed", e);
             return -1;
         }
     }
 
     public InputStream getStream() throws RepositoryException {
-        try {
-            return getDataRecord().getStream();
-        } catch (IOException e) {
-            throw new RepositoryException(e);
-        }
+        return getDataRecord().getStream();
     }
 
     /**
@@ -113,7 +109,7 @@
         return new BLOBInDataStore(store, identifier);
     }
     
-    static BLOBInDataStore getInstance(DataStore store, InputStream in) throws IOException
{
+    static BLOBInDataStore getInstance(DataStore store, InputStream in) throws DataStoreException
{
         DataRecord rec = store.addRecord(in);
         DataIdentifier identifier = rec.getIdentifier();
         return new BLOBInDataStore(store, identifier);
@@ -128,7 +124,7 @@
         return s.startsWith(PREFIX);
     }    
     
-    private DataRecord getDataRecord() throws IOException {
+    private DataRecord getDataRecord() throws DataStoreException {
         // may not keep the record, otherwise garbage collection doesn't work
         return store.getRecord(identifier);
     }

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=591286&r1=591285&r2=591286&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
Fri Nov  2 02:53:50 2007
@@ -44,11 +44,12 @@
     
     /**
      * Creates a new instance from a stream.
+     * The input stream is always closed by this method.
      *
      * @param in the input stream
      * @throws IOException 
      */    
-    private BLOBInTempFile(InputStream in, boolean temp) throws IOException {
+    private BLOBInTempFile(InputStream in, boolean temp) throws RepositoryException {
         this.temp = temp;
         OutputStream out = null;
         try {
@@ -64,11 +65,21 @@
                 out.write(buffer, 0, len);
                 length += len;                
             }
+        } catch (IOException e) {
+            throw new RepositoryException("Error creating temporary file", e); 
         } finally {
+            try {
+                in.close();
+            } catch (IOException e) {
+                // ignore
+            }
             if (out != null) {
-                out.close();
+                try {
+                    out.close();
+                } catch (IOException e) {
+                    throw new RepositoryException("Error creating temporary file", e); 
+                }
             }
-            in.close();
         }
     }
 
@@ -88,7 +99,7 @@
      *
      * @param in the stream
      */    
-    static BLOBInTempFile getInstance(InputStream in, boolean temp) throws IOException {
+    static BLOBInTempFile getInstance(InputStream in, boolean temp) throws RepositoryException
{
         return new BLOBInTempFile(in, temp);
     }
     

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java?rev=591286&r1=591285&r2=591286&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/value/InternalValue.java
Fri Nov  2 02:53:50 2007
@@ -119,26 +119,22 @@
         }
         switch (value.getType()) {
             case PropertyType.BINARY:
-                try {
-                    if (USE_DATA_STORE) {
-                        return new InternalValue(getBLOBFileValue(store, value.getStream()));
-                    }
-                    if (value instanceof BLOBFileValue) {
-                        return new InternalValue((BLOBFileValue) value);
-                    } else {
-                        InputStream stream = value.getStream();
+                if (USE_DATA_STORE) {
+                    return new InternalValue(getBLOBFileValue(store, value.getStream()));
+                }
+                if (value instanceof BLOBFileValue) {
+                    return new InternalValue((BLOBFileValue) value);
+                } else {
+                    InputStream stream = value.getStream();
+                    try {
+                        return createTemporary(stream);
+                    } finally {
                         try {
-                            return createTemporary(stream);
-                        } finally {
-                            try {
-                                stream.close();
-                            } catch (IOException e) {
-                                // ignore
-                            }
+                            stream.close();
+                        } catch (IOException e) {
+                            // ignore
                         }
                     }
-                } catch (IOException ioe) {
-                    throw new ValueFormatException(ioe.getMessage());
                 }
             case PropertyType.BOOLEAN:
                 return create(value.getBoolean());
@@ -227,11 +223,15 @@
      * @param store the data store
      * @return the internal value
      */
-    public static InternalValue createTemporary(InputStream value) throws IOException {
+    public static InternalValue createTemporary(InputStream value) throws RepositoryException
{
         if (USE_DATA_STORE) {        
             return new InternalValue(getBLOBFileValue(null, value));
         }
-        return new InternalValue(new BLOBValue(value, true));
+        try {
+            return new InternalValue(new BLOBValue(value, true));
+        } catch (IOException e) {
+            throw new RepositoryException("Error creating temporary file", e);
+        }
     }
     
     /**
@@ -243,11 +243,15 @@
      * @param store the data store or null to use a temporary file
      * @return the internal value
      */
-    public static InternalValue createTemporary(InputStream value, DataStore store) throws
IOException {
+    public static InternalValue createTemporary(InputStream value, DataStore store) throws
RepositoryException {
         if (USE_DATA_STORE) {
             return new InternalValue(getBLOBFileValue(store, value));
         }
-        return new InternalValue(new BLOBValue(value, true));
+        try {
+            return new InternalValue(new BLOBValue(value, true));
+        } catch (IOException e) {
+            throw new RepositoryException("Error creating temporary file", e);
+        }
     }
 
     /**
@@ -256,11 +260,15 @@
      * @return
      * @throws IOException
      */
-    public static InternalValue create(InputStream value) throws IOException {
+    public static InternalValue create(InputStream value) throws RepositoryException {
         if (USE_DATA_STORE) {
             return new InternalValue(getBLOBFileValue(null, value));
         }
-        return new InternalValue(new BLOBValue(value, false));
+        try {
+            return new InternalValue(new BLOBValue(value, false));
+        } catch (IOException e) {
+            throw new RepositoryException("Error creating file", e);
+        }
     }
 
     /**
@@ -447,19 +455,15 @@
         }
         if (type == PropertyType.BINARY) {
             // return a copy since the wrapped BLOBFileValue instance is mutable
+            InputStream stream = ((BLOBFileValue) val).getStream();
             try {
-                InputStream stream = ((BLOBFileValue) val).getStream();
+                return createTemporary(stream);
+            } finally {
                 try {
-                    return createTemporary(stream);
-                } finally {
-                    try {
-                        stream.close();
-                    } catch (IOException e) {
-                        // ignore
-                    }
+                    stream.close();
+                } catch (IOException e) {
+                    // ignore
                 }
-            } catch (IOException ioe) {
-                throw new RepositoryException("failed to copy binary value", ioe);
             }
         } else {
             // for all other types it's safe to return 'this' because the
@@ -590,7 +594,7 @@
         type = PropertyType.REFERENCE;
     }
     
-    private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in) throws
IOException {
+    private static BLOBFileValue getBLOBFileValue(DataStore store, InputStream in) throws
RepositoryException {
         int maxMemorySize;
         if (store != null) {
             maxMemorySize = store.getMinRecordLength() - 1;
@@ -600,13 +604,17 @@
         maxMemorySize = Math.max(0, maxMemorySize);
         byte[] buffer = new byte[maxMemorySize];
         int pos = 0, len = maxMemorySize;
-        while (pos < maxMemorySize) {
-            int l = in.read(buffer, pos, len);
-            if (l < 0) {
-                break;
+        try {
+            while (pos < maxMemorySize) {
+                int l = in.read(buffer, pos, len);
+                if (l < 0) {
+                    break;
+                }
+                pos += l;
+                len -= l;
             }
-            pos += l;
-            len -= l;
+        } catch (IOException e) {
+            throw new RepositoryException("Could not read from stream", e);
         }
         if (pos < maxMemorySize) {
             // shrink the buffer



Mime
View raw message