Author: fmui
Date: Mon Aug 12 22:34:53 2013
New Revision: 1513285
URL: http://svn.apache.org/r1513285
Log:
more code clean up
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/IOUtils.java
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/report/CoreHtmlReport.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/AbstractRunner.java
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/ConsoleRunner.java
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
Mon Aug 12 22:34:53 2013
@@ -64,6 +64,7 @@ import org.apache.chemistry.opencmis.cli
import org.apache.chemistry.opencmis.commons.data.ObjectData;
import org.apache.chemistry.opencmis.commons.data.RepositoryInfo;
import org.apache.chemistry.opencmis.commons.definitions.TypeDefinition;
+import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.commons.impl.XMLConstants;
import org.apache.chemistry.opencmis.commons.impl.XMLConstraints;
import org.apache.chemistry.opencmis.commons.impl.XMLConverter;
@@ -132,17 +133,7 @@ public class AtomPubParser {
}
} finally {
// make sure the stream is read and closed in all cases
- try {
- byte[] buffer = new byte[4096];
- while (stream.read(buffer) > -1) {
- }
- } catch (Exception e) {
- }
-
- try {
- stream.close();
- } catch (Exception e) {
- }
+ IOUtils.consumeAndClose(stream);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-android/chemistry-opencmis-android-client/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/DefaultHttpInvoker.java
Mon Aug 12 22:34:53 2013
@@ -147,7 +147,7 @@ public class DefaultHttpInvoker implemen
}
sb.append(offset.toString());
- sb.append("-");
+ sb.append('-');
if ((length != null) && (length.signum() == 1)) {
sb.append(offset.add(length.subtract(BigInteger.ONE)).toString());
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.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/AtomPubParser.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/atompub/AtomPubParser.java
Mon Aug 12 22:34:53 2013
@@ -138,14 +138,7 @@ public class AtomPubParser {
parser.close();
} finally {
// make sure the stream is read and closed in all cases
- try {
- byte[] buffer = new byte[4096];
- while (stream.read(buffer) > -1) {
- }
- } catch (Exception e) {
- }
-
- IOUtils.closeQuietly(stream);
+ IOUtils.consumeAndClose(stream);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.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/AbstractBrowserBindingService.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/browser/AbstractBrowserBindingService.java
Mon Aug 12 22:34:53 2013
@@ -314,19 +314,9 @@ public abstract class AbstractBrowserBin
} catch (Exception e) {
throw new CmisConnectionException("Parsing exception!", e);
} finally {
- try {
- char[] buffer = new char[4096];
- while (reader.read(buffer) > -1) {
- }
- } catch (Exception e) {
- }
- try {
- if (reader == null) {
- stream.close();
- } else {
- reader.close();
- }
- } catch (Exception e) {
+ IOUtils.consumeAndClose(reader);
+ if (reader == null) {
+ IOUtils.closeQuietly(stream);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.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/http/Response.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/http/Response.java
Mon Aug 12 22:34:53 2013
@@ -127,6 +127,7 @@ public class Response {
try {
length = new BigInteger(lengthStr);
} catch (NumberFormatException e) {
+ // content-length is not a number -> ignore
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.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/webservices/AbstractPortProvider.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-client/chemistry-opencmis-client-bindings/src/main/java/org/apache/chemistry/opencmis/client/bindings/spi/webservices/AbstractPortProvider.java
Mon Aug 12 22:34:53 2013
@@ -57,6 +57,7 @@ import org.apache.chemistry.opencmis.com
import
org.apache.chemistry.opencmis.commons.exceptions.CmisProxyAuthenticationException;
import org.apache.chemistry.opencmis.commons.exceptions.CmisRuntimeException;
import
org.apache.chemistry.opencmis.commons.exceptions.CmisUnauthorizedException;
+import org.apache.chemistry.opencmis.commons.impl.IOUtils;
import org.apache.chemistry.opencmis.commons.impl.UrlBuilder;
import org.apache.chemistry.opencmis.commons.impl.XMLUtils;
import org.apache.chemistry.opencmis.commons.impl.jaxb.ACLService;
@@ -621,11 +622,7 @@ public abstract class AbstractPortProvid
} catch (IOException ioe) {
throw new CmisRuntimeException("Cannot read this WSDL: " +
wsdlUrl, ioe);
} finally {
- try {
- wsdlStream.close();
- } catch (IOException ioe) {
- // ignore, there is nothing we can do
- }
+ IOUtils.closeQuietly(wsdlStream);
}
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/IOUtils.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/IOUtils.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/IOUtils.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-commons/chemistry-opencmis-commons-impl/src/main/java/org/apache/chemistry/opencmis/commons/impl/IOUtils.java
Mon Aug 12 22:34:53 2013
@@ -21,6 +21,7 @@ package org.apache.chemistry.opencmis.co
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
+import java.io.Reader;
import org.apache.chemistry.opencmis.commons.data.ContentStream;
@@ -63,4 +64,19 @@ public class IOUtils {
IOUtils.closeQuietly(stream);
}
}
+
+ /**
+ * Consumes and closes the provided reader.
+ */
+ public static void consumeAndClose(final Reader reader) {
+ try {
+ char[] buffer = new char[4096];
+ while (reader.read(buffer) > -1) {
+ }
+ } catch (IOException e) {
+ // ignore
+ } finally {
+ IOUtils.closeQuietly(reader);
+ }
+ }
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-server/chemistry-opencmis-server-support/src/main/java/org/apache/chemistry/opencmis/server/support/filter/LoggingFilter.java
Mon Aug 12 22:34:53 2013
@@ -257,19 +257,19 @@ public class LoggingFilter implements Fi
} else {
out.append(prettyPrintJson(xmlBodyBuffer.toString(), indent));
}
- out.append(line).append("\n");
+ out.append(line).append('\n');
} else {
xmlBodyBuffer.write(line.getBytes(), 0,
line.length());
}
}
} else {
LOG.debug("in XML part is: " + line);
- out.append(line).append("\n");
+ out.append(line).append('\n');
}
} else {
LOG.debug("not in XML part: " + line);
- out.append(line).append("\n");
+ out.append(line).append('\n');
boundaryFound = line.startsWith(boundary);
if (boundaryFound) {
LOG.debug("Boundardy found!");
@@ -286,16 +286,16 @@ public class LoggingFilter implements Fi
@SuppressWarnings("rawtypes")
private void logHeaders(LoggingRequestWrapper req, StringBuffer sb) {
sb.append(req.getMethod());
- sb.append(" ");
+ sb.append(' ');
sb.append(req.getRequestURI());
String queryString = req.getQueryString();
if (null != queryString && queryString.length() > 0) {
- sb.append("?");
+ sb.append('?');
sb.append(queryString);
}
- sb.append(" ");
+ sb.append(' ');
sb.append(req.getProtocol());
- sb.append("\n");
+ sb.append('\n');
Enumeration headerNames = req.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement().toString();
@@ -303,24 +303,24 @@ public class LoggingFilter implements Fi
sb.append(headerName);
sb.append(": ");
sb.append(req.getHeader(headerName));
- sb.append("\n");
+ sb.append('\n');
}
- sb.append("\n");
+ sb.append('\n');
}
private void logHeaders(LoggingResponseWrapper resp, String protocol,
StringBuffer sb) {
sb.append(protocol);
- sb.append(" ");
+ sb.append(' ');
sb.append(String.valueOf(resp.getStatus()));
- sb.append("\n");
+ sb.append('\n');
Map<String, String> headers = resp.getHeaders();
for (Map.Entry<String, String> header : headers.entrySet()) {
sb.append(header.getKey());
sb.append(": ");
sb.append(header.getValue());
- sb.append("\n");
+ sb.append('\n');
}
- sb.append("\n");
+ sb.append('\n');
}
private String getRequestFileName(int no) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/report/CoreHtmlReport.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/report/CoreHtmlReport.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/report/CoreHtmlReport.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/report/CoreHtmlReport.java
Mon Aug 12 22:34:53 2013
@@ -217,7 +217,7 @@ public class CoreHtmlReport extends Abst
if
(!ste.getClassName().startsWith("org.apache.chemistry.opencmis.tck.")) {
result.append(escape(ste.getFileName()));
if (ste.getLineNumber() > 0) {
- result.append(":");
+ result.append(':');
result.append(ste.getLineNumber());
}
} else {
@@ -238,7 +238,7 @@ public class CoreHtmlReport extends Abst
result.append(escape(ste.getFileName()));
if (ste.getLineNumber() > 0) {
- result.append(":");
+ result.append(':');
result.append(ste.getLineNumber());
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/AbstractRunner.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/runner/AbstractRunner.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/AbstractRunner.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/AbstractRunner.java
Mon Aug 12 22:34:53 2013
@@ -99,7 +99,7 @@ public abstract class AbstractRunner {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
- if (line.startsWith("#") || line.length() == 0) {
+ if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}
@@ -193,7 +193,7 @@ public abstract class AbstractRunner {
String line;
while ((line = reader.readLine()) != null) {
line = line.trim();
- if (line.startsWith("#") || line.length() == 0) {
+ if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/ConsoleRunner.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/runner/ConsoleRunner.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/ConsoleRunner.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-test/chemistry-opencmis-test-tck/src/main/java/org/apache/chemistry/opencmis/tck/runner/ConsoleRunner.java
Mon Aug 12 22:34:53 2013
@@ -64,7 +64,7 @@ public class ConsoleRunner extends Abstr
}
public void startTest(CmisTest test) {
- System.out.print(".");
+ System.out.print('.');
}
public void endTest(CmisTest test) {
Modified:
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
URL:
http://svn.apache.org/viewvc/chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java?rev=1513285&r1=1513284&r2=1513285&view=diff
==============================================================================
---
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
(original)
+++
chemistry/opencmis/trunk/chemistry-opencmis-workbench/chemistry-opencmis-workbench/src/main/java/org/apache/chemistry/opencmis/workbench/ExpertLoginTab.java
Mon Aug 12 22:34:53 2013
@@ -123,7 +123,7 @@ public class ExpertLoginTab extends Abst
for (String line : sessionParameterTextArea.getText().split("\n")) {
line = line.trim();
- if (line.startsWith("#") || (line.length() == 0)) {
+ if (line.length() == 0 || line.charAt(0) == '#') {
continue;
}