You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@chemistry.apache.org by fm...@apache.org on 2012/07/02 13:33:25 UTC
svn commit: r1356186 - in /chemistry/opencmis/trunk:
chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/
chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/c...
Author: fmui
Date: Mon Jul 2 11:33:22 2012
New Revision: 1356186
URL: http://svn.apache.org/viewvc?rev=1356186&view=rev
Log:
CMIS-548: Client: don't close input streams
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Folder.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/FormDataWriter.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ObjectService.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/VersioningService.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Converter.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/filecopy/FileCopier.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/SetAndDeleteContentTest.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/CheckInPanel.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/SetContentStreamPanel.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Document.java Mon Jul 2 11:33:22 2012
@@ -61,12 +61,20 @@ public interface Document extends Fileab
* afterwards. If the repository created a new version, this new document is
* returned. Otherwise the current document is returned.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return the updated document
*/
Document setContentStream(ContentStream contentStream, boolean overwrite);
/**
* Sets a new content stream for the document.
+ *
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
+ * @return the updated object id
*/
ObjectId setContentStream(ContentStream contentStream, boolean overwrite, boolean refresh);
@@ -104,6 +112,9 @@ public interface Document extends Fileab
* If this is a PWC (private working copy) it performs a check in. If this
* is not a PWC it an exception will be thrown.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return new document id
*/
ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream, String checkinComment,
@@ -113,6 +124,9 @@ public interface Document extends Fileab
* If this is a PWC (private working copy) it performs a check in. If this
* is not a PWC it an exception will be thrown.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return new document id
*/
ObjectId checkIn(boolean major, Map<String, ?> properties, ContentStream contentStream, String checkinComment);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Folder.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Folder.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Folder.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Folder.java Mon Jul 2 11:33:22 2012
@@ -40,6 +40,9 @@ public interface Folder extends Fileable
/**
* Creates a new document in this folder.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return the new document object or <code>null</code> if the parameter
* <code>context</code> was set to <code>null</code>
*/
@@ -49,6 +52,9 @@ public interface Folder extends Fileable
/**
* Creates a new document in this folder.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return the new document object
*/
Document createDocument(Map<String, ?> properties, ContentStream contentStream, VersioningState versioningState);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-api/src/main/java/org/apache/chemistry/opencmis/client/api/Session.java Mon Jul 2 11:33:22 2012
@@ -357,6 +357,9 @@ public interface Session extends Seriali
/**
* Creates a new document.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return the object id of the new document
*
* @see Folder#createDocument(Map, ContentStream, VersioningState, List,
@@ -368,6 +371,9 @@ public interface Session extends Seriali
/**
* Creates a new document.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @return the object id of the new document
*
* @see Folder#createDocument(Map, ContentStream, VersioningState, List,
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomEntryWriter.java Mon Jul 2 11:33:22 2012
@@ -18,11 +18,12 @@
*/
package org.apache.chemistry.opencmis.client.bindings.spi.atompub;
-import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.*;
+import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_ATOM_ID;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_ATOM_TITLE;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_ATOM_UPDATED;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_CONTENT;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_CONTENT_BASE64;
+import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_CONTENT_FILENAME;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_CONTENT_MEDIATYPE;
import static org.apache.chemistry.opencmis.client.bindings.spi.atompub.CmisAtomPubConstants.TAG_ENTRY;
@@ -39,6 +40,7 @@ import javax.xml.stream.XMLOutputFactory
import javax.xml.stream.XMLStreamWriter;
import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
import org.apache.chemistry.opencmis.commons.exceptions.CmisInvalidArgumentException;
import org.apache.chemistry.opencmis.commons.impl.Base64;
import org.apache.chemistry.opencmis.commons.impl.Constants;
@@ -60,39 +62,42 @@ public class AtomEntryWriter {
private static final int BUFFER_SIZE = 64 * 1024;
private final CmisObjectType object;
+ private final ContentStream contentStream;
private final InputStream stream;
- private final String mediaType;
- private final String filename;
/**
* Constructor.
*/
public AtomEntryWriter(CmisObjectType object) {
- this(object, null, null, null);
+ this(object, null);
}
/**
* Constructor.
*/
- public AtomEntryWriter(CmisObjectType object, String mediaType, String filename, InputStream stream) {
+ public AtomEntryWriter(CmisObjectType object, ContentStream contentStream) {
if ((object == null) || (object.getProperties() == null)) {
throw new CmisInvalidArgumentException("Object and properties must not be null!");
}
- if ((stream != null) && (mediaType == null)) {
+ if ((contentStream != null) && (contentStream.getMimeType() == null)) {
throw new CmisInvalidArgumentException("Media type must be set if a stream is present!");
}
this.object = object;
- this.mediaType = mediaType;
- this.filename = filename;
+ this.contentStream = contentStream;
+ if (contentStream != null && contentStream.getStream() != null) {
+ InputStream in = contentStream.getStream();
- if (stream != null && !(stream instanceof BufferedInputStream) && !(stream instanceof ByteArrayInputStream)) {
// avoid double buffering
- stream = new BufferedInputStream(stream, BUFFER_SIZE);
+ if (!(in instanceof BufferedInputStream) && !(in instanceof ByteArrayInputStream)) {
+ stream = new BufferedInputStream(in, BUFFER_SIZE);
+ } else {
+ stream = in;
+ }
+ } else {
+ stream = null;
}
-
- this.stream = stream;
}
/**
@@ -115,7 +120,7 @@ public class AtomEntryWriter {
writer.writeNamespace(PREFIX_ATOM, Constants.NAMESPACE_ATOM);
writer.writeNamespace(PREFIX_CMIS, Constants.NAMESPACE_CMIS);
writer.writeNamespace(PREFIX_RESTATOM, Constants.NAMESPACE_RESTATOM);
- if (filename != null) {
+ if (contentStream != null && contentStream.getFileName() != null) {
writer.writeNamespace(PREFIX_APACHE_CHEMISTY, Constants.NAMESPACE_APACHE_CHEMISTRY);
}
@@ -139,12 +144,12 @@ public class AtomEntryWriter {
writer.writeStartElement(Constants.NAMESPACE_RESTATOM, TAG_CONTENT);
writer.writeStartElement(Constants.NAMESPACE_RESTATOM, TAG_CONTENT_MEDIATYPE);
- writer.writeCharacters(mediaType);
+ writer.writeCharacters(contentStream.getMimeType());
writer.writeEndElement();
- if (filename != null) {
+ if (contentStream.getFileName() != null) {
writer.writeStartElement(Constants.NAMESPACE_APACHE_CHEMISTRY, TAG_CONTENT_FILENAME);
- writer.writeCharacters(filename);
+ writer.writeCharacters(contentStream.getFileName());
writer.writeEndElement();
}
@@ -201,7 +206,5 @@ public class AtomEntryWriter {
writer.writeCharacters(new String(buffer, 0, b, "US-ASCII"));
}
}
-
- b64stream.close();
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/ObjectServiceImpl.java Mon Jul 2 11:33:22 2012
@@ -113,17 +113,7 @@ public class ObjectServiceImpl extends A
object.setProperties(convert(properties));
object.setPolicyIds(convertPolicyIds(policies));
- String mediaType = null;
- String filename = null;
- InputStream stream = null;
-
- if (contentStream != null) {
- mediaType = contentStream.getMimeType();
- filename = contentStream.getFileName();
- stream = contentStream.getStream();
- }
-
- final AtomEntryWriter entryWriter = new AtomEntryWriter(object, mediaType, filename, stream);
+ final AtomEntryWriter entryWriter = new AtomEntryWriter(object, contentStream);
// post the new folder object
HttpUtils.Response resp = post(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
@@ -625,8 +615,6 @@ public class ObjectServiceImpl extends A
while ((b = stream.read(buffer)) > -1) {
out.write(buffer, 0, b);
}
-
- stream.close();
}
});
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/VersioningServiceImpl.java Mon Jul 2 11:33:22 2012
@@ -21,7 +21,6 @@ package org.apache.chemistry.opencmis.cl
import static org.apache.chemistry.opencmis.commons.impl.Converter.convert;
import static org.apache.chemistry.opencmis.commons.impl.Converter.convertPolicyIds;
-import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
@@ -165,17 +164,7 @@ public class VersioningServiceImpl exten
object.setProperties(new CmisPropertiesType());
}
- String mediaType = null;
- String filename = null;
- InputStream stream = null;
-
- if (contentStream != null) {
- mediaType = contentStream.getMimeType();
- filename = contentStream.getFileName();
- stream = contentStream.getStream();
- }
-
- final AtomEntryWriter entryWriter = new AtomEntryWriter(object, mediaType, filename, stream);
+ final AtomEntryWriter entryWriter = new AtomEntryWriter(object, contentStream);
// update
HttpUtils.Response resp = put(url, Constants.MEDIATYPE_ENTRY, new HttpUtils.Output() {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/FormDataWriter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/FormDataWriter.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/FormDataWriter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/FormDataWriter.java Mon Jul 2 11:33:22 2012
@@ -224,8 +224,6 @@ public class FormDataWriter {
writeLine(out);
writeLine(out, "--" + boundary + "--");
-
- stream.close();
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/test/java/org/apache/chemistry/opencmis/client/bindings/atompub/AtomParserTest.java Mon Jul 2 11:33:22 2012
@@ -33,6 +33,8 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomElement;
import org.apache.chemistry.opencmis.client.bindings.spi.atompub.objects.AtomEntry;
import org.apache.chemistry.opencmis.commons.PropertyIds;
+import org.apache.chemistry.opencmis.commons.data.ContentStream;
+import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisObjectType;
import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisPropertiesType;
import org.apache.chemistry.opencmis.commons.impl.jaxb.CmisProperty;
@@ -77,7 +79,9 @@ public class AtomParserTest extends Test
object1.setProperties(properties);
// write the entry
- AtomEntryWriter aew = new AtomEntryWriter(object1, CONTENT_TYPE, null, new ByteArrayInputStream(CONTENT));
+ ContentStream contentStream = new ContentStreamImpl(null, BigInteger.valueOf(CONTENT.length), CONTENT_TYPE,
+ new ByteArrayInputStream(CONTENT));
+ AtomEntryWriter aew = new AtomEntryWriter(object1, contentStream);
aew.write(bao);
byte[] entryContent = bao.toByteArray();
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/runtime/DocumentImpl.java Mon Jul 2 11:33:22 2012
@@ -18,6 +18,7 @@
*/
package org.apache.chemistry.opencmis.client.runtime;
+import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
@@ -190,8 +191,19 @@ public class DocumentImpl extends Abstra
newProperties.putAll(properties);
}
- return getSession().createDocument(newProperties, targetFolderId, allPropsDoc.getContentStream(),
- versioningState, policies, addAces, removeAces);
+ ContentStream contentStream = allPropsDoc.getContentStream();
+ try {
+ return getSession().createDocument(newProperties, targetFolderId, contentStream, versioningState, policies,
+ addAces, removeAces);
+ } finally {
+ if (contentStream != null && contentStream.getStream() != null) {
+ try {
+ contentStream.getStream().close();
+ } catch (IOException ioe) {
+ throw new CmisRuntimeException("Cannot close source stream!", ioe);
+ }
+ }
+ }
}
public void deleteAllVersions() {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-impl/src/main/java/org/apache/chemistry/opencmis/client/util/FileUtils.java Mon Jul 2 11:33:22 2012
@@ -43,6 +43,7 @@ import org.apache.chemistry.opencmis.com
import org.apache.chemistry.opencmis.commons.enums.UnfileObject;
import org.apache.chemistry.opencmis.commons.enums.VersioningState;
import org.apache.chemistry.opencmis.commons.exceptions.CmisBaseException;
+import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import org.apache.chemistry.opencmis.commons.impl.MimeTypes;
import org.apache.chemistry.opencmis.commons.impl.dataobjects.ContentStreamImpl;
@@ -132,10 +133,20 @@ public class FileUtils {
properties.put(PropertyIds.OBJECT_TYPE_ID, type);
properties.put(PropertyIds.NAME, name);
- ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(file.length()), mimetype,
- new FileInputStream(file));
+ InputStream stream = new FileInputStream(file);
+ ContentStream contentStream = new ContentStreamImpl(name, BigInteger.valueOf(file.length()), mimetype, stream);
- return parentFolder.createDocument(properties, contentStream, versioningState);
+ try {
+ return parentFolder.createDocument(properties, contentStream, versioningState);
+ } finally {
+ if (stream != null) {
+ try {
+ stream.close();
+ } catch (IOException ioe) {
+ throw new CmisRuntimeException("Cannot close source stream!", ioe);
+ }
+ }
+ }
}
/**
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ObjectService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ObjectService.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ObjectService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/ObjectService.java Mon Jul 2 11:33:22 2012
@@ -49,6 +49,9 @@ public interface ObjectService {
* Creates a document object of the specified type (given by the
* cmis:objectTypeId property) in the (optionally) specified location.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @param repositoryId
* the identifier for the repository
* @param properties
@@ -227,7 +230,7 @@ public interface ObjectService {
* (default is repository specific)
* @param includeAllowableActions
* <em>(optional)</em> if <code>true</code>, then the repository
- * must return the available actions for the object (default is
+ * must return the allowable actions for the object (default is
* <code>false</code>)
* @param includeRelationships
* <em>(optional)</em> indicates what relationships in which the
@@ -300,7 +303,7 @@ public interface ObjectService {
* (default is repository specific)
* @param includeAllowableActions
* <em>(optional)</em> if <code>true</code>, then the repository
- * must return the available actions for the object (default is
+ * must return the allowable actions for the object (default is
* <code>false</code>)
* @param includeRelationships
* <em>(optional)</em> indicates what relationships in which the
@@ -412,6 +415,9 @@ public interface ObjectService {
/**
* Sets the content stream for the specified document object.
*
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
* @param repositoryId
* the identifier for the repository
* @param objectId
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/VersioningService.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/VersioningService.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/VersioningService.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-api/src/main/java/org/apache/chemistry/opencmis/commons/spi/VersioningService.java Mon Jul 2 11:33:22 2012
@@ -40,16 +40,28 @@ import org.apache.chemistry.opencmis.com
public interface VersioningService {
/**
* Create a private working copy of the document.
+ *
+ * @param repositoryId
+ * the identifier for the repository
*/
void checkOut(String repositoryId, Holder<String> objectId, ExtensionsData extension, Holder<Boolean> contentCopied);
/**
* Reverses the effect of a check-out.
+ *
+ * @param repositoryId
+ * the identifier for the repository
*/
void cancelCheckOut(String repositoryId, String objectId, ExtensionsData extension);
/**
* Checks-in the private working copy (PWC) document.
+ *
+ * The stream in <code>contentStream</code> is consumed but not closed by
+ * this method.
+ *
+ * @param repositoryId
+ * the identifier for the repository
*/
void checkIn(String repositoryId, Holder<String> objectId, Boolean major, Properties properties,
ContentStream contentStream, String checkinComment, List<String> policies, Acl addAces, Acl removeAces,
@@ -57,6 +69,9 @@ public interface VersioningService {
/**
* Get the latest document object in the version series.
+ *
+ * @param repositoryId
+ * the identifier for the repository
*/
ObjectData getObjectOfLatestVersion(String repositoryId, String objectId, String versionSeriesId, Boolean major,
String filter, Boolean includeAllowableActions, IncludeRelationships includeRelationships,
@@ -65,6 +80,9 @@ public interface VersioningService {
/**
* Get a subset of the properties for the latest document object in the
* version series.
+ *
+ * @param repositoryId
+ * the identifier for the repository
*/
Properties getPropertiesOfLatestVersion(String repositoryId, String objectId, String versionSeriesId,
Boolean major, String filter, ExtensionsData extension);
@@ -72,6 +90,26 @@ public interface VersioningService {
/**
* Returns the list of all document objects in the specified version series,
* sorted by the property "cmis:creationDate" descending.
+ *
+ * Either the <code>objectId</code> or the <code>versionSeriesId</code>
+ * parameter must be set.
+ *
+ * @param repositoryId
+ * the identifier for the repository
+ * @param objectId
+ * the identifier for the object
+ * @param versionSeriesId
+ * the identifier for the object
+ * @param filter
+ * <em>(optional)</em> a comma-separated list of query names that
+ * defines which properties must be returned by the repository
+ * (default is repository specific)
+ * @param includeAllowableActions
+ * <em>(optional)</em> if <code>true</code>, then the repository
+ * must return the allowable actions for the objects (default is
+ * <code>false</code>)
+ *
+ * @return the complete version history of the version series
*/
List<ObjectData> getAllVersions(String repositoryId, String objectId, String versionSeriesId, String filter,
Boolean includeAllowableActions, ExtensionsData extension);
Modified: chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Converter.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Converter.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Converter.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/Converter.java Mon Jul 2 11:33:22 2012
@@ -18,6 +18,9 @@
*/
package org.apache.chemistry.opencmis.commons.impl;
+import java.io.BufferedInputStream;
+import java.io.ByteArrayInputStream;
+import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -240,6 +243,7 @@ import com.sun.xml.ws.developer.Streamin
public final class Converter {
private static final String DEFAULT_EXTENSION_NS = "http://chemistry.apache.org/opencmis/extension";
+ private static final int BUFFER_SIZE = 64 * 1024;
/**
* Private constructor.
@@ -2377,6 +2381,16 @@ public final class Converter {
result.setLength(contentStream.getBigLength());
result.setMimeType(contentStream.getMimeType());
+ InputStream in = contentStream.getStream();
+ final InputStream stream;
+
+ // avoid double buffering
+ if (!(in instanceof BufferedInputStream) && !(in instanceof ByteArrayInputStream)) {
+ stream = new BufferedInputStream(in, BUFFER_SIZE);
+ } else {
+ stream = contentStream.getStream();
+ }
+
result.setStream(new DataHandler(new DataSource() {
public OutputStream getOutputStream() throws IOException {
@@ -2388,7 +2402,12 @@ public final class Converter {
}
public InputStream getInputStream() throws IOException {
- return contentStream.getStream();
+ return new FilterInputStream(stream) {
+ @Override
+ public void close() throws IOException {
+ // prevent closing
+ }
+ };
}
public String getContentType() {
@@ -2648,11 +2667,11 @@ public final class Converter {
attributes = new HashMap<String, String>();
for (int i = 0; i < node.getAttributes().getLength(); i++) {
Node attrNode = node.getAttributes().item(i);
-
+
String attrNamespace = attrNode.getNamespaceURI();
-
- if (attrNamespace == null || attrNamespace.equals(namespace)) {
- attributes.put(attrNode.getLocalName(), attrNode.getNodeValue());
+
+ if (attrNamespace == null || attrNamespace.equals(namespace)) {
+ attributes.put(attrNode.getLocalName(), attrNode.getNodeValue());
}
}
}
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/filecopy/FileCopier.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/filecopy/FileCopier.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/filecopy/FileCopier.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-client/src/main/java/org/apache/chemistry/opencmis/client/filecopy/FileCopier.java Mon Jul 2 11:33:22 2012
@@ -142,6 +142,8 @@ public class FileCopier {
properties.put(PropertyIds.NAME, f.getName().replaceAll(" ", "_"));
LOG.debug("uploading document with content lenth: " + contentStream.getLength());
Document doc = parentFolder.createDocument(properties, contentStream, VersioningState.NONE);
+ is.close();
+
id = doc.getId();
LOG.info("New document created with id: " + id + ", name: " + properties.get(PropertyIds.NAME) + " in folder: " + parentFolder.getId());
} catch (Exception e) {
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/impl/AbstractSessionTest.java Mon Jul 2 11:33:22 2012
@@ -366,6 +366,8 @@ public abstract class AbstractSessionTes
// create the document
result = parent.createDocument(properties, contentStream, versioningState, null, null, null,
SELECT_ALL_NO_CACHE_OC);
+
+ contentStream.getStream().close();
} catch (Exception e) {
addResult(createResult(UNEXPECTED_EXCEPTION, "Document could not be created! Exception: " + e.getMessage(),
e, true));
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/SetAndDeleteContentTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/SetAndDeleteContentTest.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/SetAndDeleteContentTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/crud/SetAndDeleteContentTest.java Mon Jul 2 11:33:22 2012
@@ -131,6 +131,11 @@ public class SetAndDeleteContentTest ext
ObjectId newObjectId = workDoc.setContentStream(contentStream, true, true);
+ try {
+ contentStream.getStream().close();
+ } catch (Exception e) {
+ }
+
// setContentStream may have created a new version
Document contentDoc = getNewVersion(session, workDoc, checkedout, newObjectId, "setContentStream()");
Modified: chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/tests/versioning/VersionDeleteTest.java Mon Jul 2 11:33:22 2012
@@ -22,6 +22,7 @@ import static org.apache.chemistry.openc
import static org.apache.chemistry.opencmis.tck.CmisTestResultStatus.SKIPPED;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.util.List;
@@ -96,6 +97,11 @@ public class VersionDeleteTest extends A
"text/plain", new ByteArrayInputStream(contentBytes));
ObjectId newVersionId = pwc.checkIn(true, null, contentStream, "test version " + version);
+ try {
+ contentStream.getStream().close();
+ } catch (IOException ioe) {
+ }
+
Document newVersion = (Document) session.getObject(newVersionId, SELECT_ALL_NO_CACHE_OC);
addResult(checkObject(session, newVersion, getAllProperties(newVersion), "Version " + version + " compliance"));
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/CheckInPanel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/CheckInPanel.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/CheckInPanel.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/CheckInPanel.java Mon Jul 2 11:33:22 2012
@@ -18,6 +18,8 @@
*/
package org.apache.chemistry.opencmis.workbench.actions;
+import java.io.IOException;
+
import javax.swing.JCheckBox;
import javax.swing.JTextField;
@@ -64,7 +66,19 @@ public class CheckInPanel extends Action
@Override
public boolean doAction() throws Exception {
ContentStream content = getClientModel().createContentStream(filenameField.getText());
- ((Document) getObject()).checkIn(majorBox.isSelected(), null, content, null, null, null, null);
+
+ try {
+ ((Document) getObject()).checkIn(majorBox.isSelected(), null, content, null, null, null, null);
+ } finally {
+ if (content != null && content.getStream() != null) {
+ try {
+ content.getStream().close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+
return false;
}
}
\ No newline at end of file
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/SetContentStreamPanel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/SetContentStreamPanel.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/SetContentStreamPanel.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/actions/SetContentStreamPanel.java Mon Jul 2 11:33:22 2012
@@ -18,6 +18,8 @@
*/
package org.apache.chemistry.opencmis.workbench.actions;
+import java.io.IOException;
+
import javax.swing.JCheckBox;
import javax.swing.JTextField;
@@ -64,7 +66,18 @@ public class SetContentStreamPanel exten
@Override
public boolean doAction() throws Exception {
ContentStream content = getClientModel().createContentStream(filenameField.getText());
- ((Document) getObject()).setContentStream(content, overwriteBox.isSelected());
+
+ try {
+ ((Document) getObject()).setContentStream(content, overwriteBox.isSelected());
+ } finally {
+ if (content != null && content.getStream() != null) {
+ try {
+ content.getStream().close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
return true;
}
}
\ No newline at end of file
Modified: chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java
URL: http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java?rev=1356186&r1=1356185&r2=1356186&view=diff
==============================================================================
--- chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java (original)
+++ chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/model/ClientModel.java Mon Jul 2 11:33:22 2012
@@ -257,8 +257,15 @@ public class ClientModel {
properties.put(PropertyIds.OBJECT_TYPE_ID, type);
ContentStream content = createContentStream(filename);
- return clientSession.getSession().createDocument(properties, (unfiled ? null : currentFolder), content,
- versioningState, null, null, null);
+
+ try {
+ return clientSession.getSession().createDocument(properties, (unfiled ? null : currentFolder), content,
+ versioningState, null, null, null);
+ } finally {
+ if (content != null && content.getStream() != null) {
+ content.getStream().close();
+ }
+ }
}
public ContentStream createContentStream(String name, long length, long seed) throws Exception {
@@ -273,8 +280,14 @@ public class ClientModel {
properties.put(PropertyIds.OBJECT_TYPE_ID, type);
ContentStream content = createContentStream(name, length, seed);
- return clientSession.getSession().createDocument(properties, (unfiled ? null : currentFolder), content,
- versioningState, null, null, null);
+ try {
+ return clientSession.getSession().createDocument(properties, (unfiled ? null : currentFolder), content,
+ versioningState, null, null, null);
+ } finally {
+ if (content != null && content.getStream() != null) {
+ content.getStream().close();
+ }
+ }
}
public synchronized ObjectId createFolder(String name, String type) throws Exception {