You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@santuario.apache.org by co...@apache.org on 2016/10/18 11:25:42 UTC
svn commit: r1765415 - in
/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security:
stax/impl/processor/input/ stax/impl/processor/output/
stax/impl/securityToken/ stax/impl/transformer/
stax/impl/transformer/canonicalizer/ stax/impl/ut...
Author: coheigea
Date: Tue Oct 18 11:25:42 2016
New Revision: 1765415
URL: http://svn.apache.org/viewvc?rev=1765415&view=rev
Log:
Consolidating on a single set of Unsync Streams for both DOM + StAX code
Added:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayInputStream.java
- copied, changed from r1765231, santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayInputStream.java
Removed:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedBufferedOutputStream.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayInputStream.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayOutputStream.java
Modified:
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/FullyBufferedOutputStream.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java
santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractDecryptInputProcessor.java Tue Oct 18 11:25:42 2016
@@ -22,6 +22,7 @@ import org.apache.commons.codec.binary.B
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
import org.apache.xml.security.stax.securityToken.SecurityTokenProvider;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.xml.security.binding.xmldsig.KeyInfoType;
@@ -347,7 +348,7 @@ public abstract class AbstractDecryptInp
}
stringBuilder.append('>');
- return new UnsynchronizedByteArrayInputStream(stringBuilder.toString().getBytes("UTF-8"));
+ return new UnsyncByteArrayInputStream(stringBuilder.toString().getBytes("UTF-8"));
}
private InputStream writeWrapperEndElement() throws IOException {
@@ -358,7 +359,7 @@ public abstract class AbstractDecryptInp
stringBuilder.append(':');
stringBuilder.append(wrapperElementName.getLocalPart());
stringBuilder.append('>');
- return new UnsynchronizedByteArrayInputStream(stringBuilder.toString().getBytes("UTF-8"));
+ return new UnsyncByteArrayInputStream(stringBuilder.toString().getBytes("UTF-8"));
}
private void forwardToWrapperElement(XMLStreamReader xmlStreamReader) throws XMLStreamException {
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureInputHandler.java Tue Oct 18 11:25:42 2016
@@ -26,6 +26,9 @@ import org.apache.xml.security.exception
import org.apache.xml.security.stax.ext.*;
import org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_Excl;
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
+import org.apache.xml.security.utils.UnsyncBufferedOutputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.ext.stax.XMLSecEventFactory;
import org.apache.xml.security.stax.impl.algorithms.SignatureAlgorithm;
@@ -146,7 +149,7 @@ public abstract class AbstractSignatureI
Deque<XMLSecEvent> signedInfoDeque = new ArrayDeque<XMLSecEvent>();
- UnsynchronizedByteArrayOutputStream unsynchronizedByteArrayOutputStream = new UnsynchronizedByteArrayOutputStream();
+ UnsyncByteArrayOutputStream unsynchronizedByteArrayOutputStream = new UnsyncByteArrayOutputStream();
Transformer transformer = XMLSecurityUtils.getTransformer(
null,
unsynchronizedByteArrayOutputStream,
@@ -193,7 +196,7 @@ public abstract class AbstractSignatureI
XMLStreamReader xmlStreamReader = inputProcessorChain.getSecurityContext().
<XMLInputFactory>get(XMLSecurityConstants.XMLINPUTFACTORY).
- createXMLStreamReader(new UnsynchronizedByteArrayInputStream(unsynchronizedByteArrayOutputStream.toByteArray()));
+ createXMLStreamReader(new UnsyncByteArrayInputStream(unsynchronizedByteArrayOutputStream.toByteArray()));
while (xmlStreamReader.hasNext()) {
XMLSecEvent xmlSecEvent = XMLSecEventFactory.allocate(xmlStreamReader, null);
@@ -305,7 +308,7 @@ public abstract class AbstractSignatureI
algorithmURI);
signatureAlgorithm.engineInitVerify(verifyKey);
signerOutputStream = new SignerOutputStream(signatureAlgorithm);
- bufferedSignerOutputStream = new UnsynchronizedBufferedOutputStream(signerOutputStream);
+ bufferedSignerOutputStream = new UnsyncBufferedOutputStream(signerOutputStream);
final CanonicalizationMethodType canonicalizationMethodType =
signatureType.getSignedInfo().getCanonicalizationMethod();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/input/AbstractSignatureReferenceVerifyInputProcessor.java Tue Oct 18 11:25:42 2016
@@ -21,6 +21,7 @@ package org.apache.xml.security.stax.imp
import org.apache.commons.codec.binary.Base64;
import org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_Excl;
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
+import org.apache.xml.security.utils.UnsyncBufferedOutputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.xml.security.binding.excc14n.InclusiveNamespaces;
@@ -39,7 +40,6 @@ import org.apache.xml.security.stax.impl
import org.apache.xml.security.stax.impl.util.DigestOutputStream;
import org.apache.xml.security.stax.impl.util.IDGenerator;
import org.apache.xml.security.stax.impl.util.KeyValue;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedBufferedOutputStream;
import org.apache.xml.security.stax.securityEvent.AlgorithmSuiteSecurityEvent;
import javax.xml.namespace.QName;
@@ -264,8 +264,8 @@ public abstract class AbstractSignatureR
try {
DigestOutputStream digestOutputStream =
createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
- UnsynchronizedBufferedOutputStream bufferedDigestOutputStream =
- new UnsynchronizedBufferedOutputStream(digestOutputStream);
+ UnsyncBufferedOutputStream bufferedDigestOutputStream =
+ new UnsyncBufferedOutputStream(digestOutputStream);
if (referenceType.getTransforms() != null) {
Transformer transformer =
@@ -422,7 +422,7 @@ public abstract class AbstractSignatureR
this.setStartElement(startElement);
this.setReferenceType(referenceType);
this.digestOutputStream = createMessageDigestOutputStream(referenceType, inputProcessorChain.getSecurityContext());
- this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(this.getDigestOutputStream());
+ this.bufferedDigestOutputStream = new UnsyncBufferedOutputStream(this.getDigestOutputStream());
this.transformer = buildTransformerChain(referenceType, bufferedDigestOutputStream, inputProcessorChain);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureEndingOutputProcessor.java Tue Oct 18 11:25:42 2016
@@ -44,10 +44,10 @@ import org.apache.xml.security.stax.impl
import org.apache.xml.security.stax.impl.transformer.canonicalizer.Canonicalizer20010315_Excl;
import org.apache.xml.security.stax.impl.util.IDGenerator;
import org.apache.xml.security.stax.impl.util.SignerOutputStream;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedBufferedOutputStream;
import org.apache.xml.security.stax.securityToken.OutboundSecurityToken;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
import org.apache.xml.security.stax.securityToken.SecurityTokenProvider;
+import org.apache.xml.security.utils.UnsyncBufferedOutputStream;
/**
* @author $Author$
@@ -242,7 +242,7 @@ public abstract class AbstractSignatureE
public void init(OutputProcessorChain outputProcessorChain) throws XMLSecurityException {
this.signerOutputStream = new SignerOutputStream(this.signatureAlgorithm);
- this.bufferedSignerOutputStream = new UnsynchronizedBufferedOutputStream(this.signerOutputStream);
+ this.bufferedSignerOutputStream = new UnsyncBufferedOutputStream(this.signerOutputStream);
final String canonicalizationAlgorithm = getSecurityProperties().getSignatureCanonicalizationAlgorithm();
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/processor/output/AbstractSignatureOutputProcessor.java Tue Oct 18 11:25:42 2016
@@ -31,7 +31,7 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.impl.SignaturePartDef;
import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
import org.apache.xml.security.stax.impl.util.DigestOutputStream;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedBufferedOutputStream;
+import org.apache.xml.security.utils.UnsyncBufferedOutputStream;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
@@ -266,7 +266,7 @@ public abstract class AbstractSignatureO
@Override
public void init(OutputProcessorChain outputProcessorChain) throws XMLSecurityException {
this.digestOutputStream = createMessageDigestOutputStream(signaturePartDef.getDigestAlgo());
- this.bufferedDigestOutputStream = new UnsynchronizedBufferedOutputStream(digestOutputStream);
+ this.bufferedDigestOutputStream = new UnsyncBufferedOutputStream(digestOutputStream);
this.transformer = buildTransformerChain(this.bufferedDigestOutputStream, signaturePartDef, xmlSecStartElement);
super.init(outputProcessorChain);
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/securityToken/SecurityTokenFactoryImpl.java Tue Oct 18 11:25:42 2016
@@ -27,8 +27,8 @@ import org.apache.xml.security.stax.secu
import org.apache.xml.security.stax.securityToken.InboundSecurityToken;
import org.apache.xml.security.stax.securityToken.SecurityTokenConstants;
import org.apache.xml.security.stax.securityToken.SecurityTokenFactory;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
import org.apache.xml.security.utils.RFC2253Parser;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
import java.io.InputStream;
import java.security.Key;
@@ -268,7 +268,7 @@ public class SecurityTokenFactoryImpl ex
*/
private static X509Certificate getCertificateFromBytes(byte[] data)
throws XMLSecurityException {
- InputStream in = new UnsynchronizedByteArrayInputStream(data);
+ InputStream in = new UnsyncByteArrayInputStream(data);
try {
CertificateFactory factory = CertificateFactory.getInstance("X.509");
return (X509Certificate) factory.generateCertificate(in);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformBase64Decode.java Tue Oct 18 11:25:42 2016
@@ -24,8 +24,8 @@ import org.apache.xml.security.exception
import org.apache.xml.security.stax.ext.XMLSecurityConstants;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayOutputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
import javax.xml.stream.XMLStreamConstants;
import javax.xml.stream.XMLStreamException;
@@ -89,13 +89,13 @@ public class TransformBase64Decode exten
case XMLSecEvent: {
childOutputMethod = new ChildOutputMethod() {
- private UnsynchronizedByteArrayOutputStream byteArrayOutputStream;
+ private UnsyncByteArrayOutputStream byteArrayOutputStream;
private Base64OutputStream base64OutputStream;
@Override
public void transform(Object object) throws XMLStreamException {
if (base64OutputStream == null) {
- byteArrayOutputStream = new UnsynchronizedByteArrayOutputStream();
+ byteArrayOutputStream = new UnsyncByteArrayOutputStream();
base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
}
try {
@@ -115,7 +115,7 @@ public class TransformBase64Decode exten
XMLEventReaderInputProcessor xmlEventReaderInputProcessor
= new XMLEventReaderInputProcessor(
null,
- getXmlInputFactory().createXMLStreamReader(new UnsynchronizedByteArrayInputStream(byteArrayOutputStream.toByteArray()))
+ getXmlInputFactory().createXMLStreamReader(new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray()))
);
try {
@@ -135,13 +135,13 @@ public class TransformBase64Decode exten
case InputStream: {
childOutputMethod = new ChildOutputMethod() {
- private UnsynchronizedByteArrayOutputStream byteArrayOutputStream;
+ private UnsyncByteArrayOutputStream byteArrayOutputStream;
private Base64OutputStream base64OutputStream;
@Override
public void transform(Object object) throws XMLStreamException {
if (base64OutputStream == null) {
- byteArrayOutputStream = new UnsynchronizedByteArrayOutputStream();
+ byteArrayOutputStream = new UnsyncByteArrayOutputStream();
base64OutputStream = new Base64OutputStream(byteArrayOutputStream, false);
}
try {
@@ -158,7 +158,7 @@ public class TransformBase64Decode exten
} catch (IOException e) {
throw new XMLStreamException(e);
}
- getTransformer().transform(new UnsynchronizedByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+ getTransformer().transform(new UnsyncByteArrayInputStream(byteArrayOutputStream.toByteArray()));
getTransformer().doFinal();
}
};
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/TransformIdentity.java Tue Oct 18 11:25:42 2016
@@ -24,8 +24,8 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.ext.XMLSecurityUtils;
import org.apache.xml.security.stax.ext.stax.XMLSecEvent;
import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayOutputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
import javax.xml.stream.*;
import java.io.*;
@@ -144,13 +144,13 @@ public class TransformIdentity implement
case InputStream: {
childOutputMethod = new ChildOutputMethod() {
- private UnsynchronizedByteArrayOutputStream baos;
+ private UnsyncByteArrayOutputStream baos;
private XMLEventWriter xmlEventWriter;
@Override
public void transform(Object object) throws XMLStreamException {
if (xmlEventWriter == null) {
- baos = new UnsynchronizedByteArrayOutputStream();
+ baos = new UnsyncByteArrayOutputStream();
xmlEventWriter = getXmlOutputFactory().createXMLEventWriter(baos);
}
@@ -160,7 +160,7 @@ public class TransformIdentity implement
@Override
public void doFinal() throws XMLStreamException {
xmlEventWriter.close();
- getTransformer().transform(new UnsynchronizedByteArrayInputStream(baos.toByteArray()));
+ getTransformer().transform(new UnsyncByteArrayInputStream(baos.toByteArray()));
getTransformer().doFinal();
}
};
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/transformer/canonicalizer/CanonicalizerBase.java Tue Oct 18 11:25:42 2016
@@ -26,8 +26,8 @@ import org.apache.xml.security.stax.ext.
import org.apache.xml.security.stax.ext.stax.*;
import org.apache.xml.security.stax.impl.processor.input.XMLEventReaderInputProcessor;
import org.apache.xml.security.stax.impl.transformer.TransformIdentity;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayInputStream;
-import org.apache.xml.security.stax.impl.util.UnsynchronizedByteArrayOutputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayInputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
import javax.xml.namespace.QName;
import javax.xml.stream.*;
@@ -84,7 +84,7 @@ public abstract class CanonicalizerBase
@Override
public void setTransformer(Transformer transformer) throws XMLSecurityException {
//we support only transformers which takes an InputStream otherwise we will break the C14N
- setOutputStream(new UnsynchronizedByteArrayOutputStream());
+ setOutputStream(new UnsyncByteArrayOutputStream());
super.setTransformer(transformer);
}
@@ -390,8 +390,8 @@ public abstract class CanonicalizerBase
@Override
public void doFinal() throws XMLStreamException {
if (getTransformer() != null) {
- UnsynchronizedByteArrayOutputStream baos = (UnsynchronizedByteArrayOutputStream)getOutputStream();
- getTransformer().transform(new UnsynchronizedByteArrayInputStream(baos.toByteArray()));
+ UnsyncByteArrayOutputStream baos = (UnsyncByteArrayOutputStream)getOutputStream();
+ getTransformer().transform(new UnsyncByteArrayInputStream(baos.toByteArray()));
getTransformer().doFinal();
}
}
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/FullyBufferedOutputStream.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/FullyBufferedOutputStream.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/FullyBufferedOutputStream.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/FullyBufferedOutputStream.java Tue Oct 18 11:25:42 2016
@@ -22,9 +22,11 @@ import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import org.apache.xml.security.utils.UnsyncByteArrayOutputStream;
+
public class FullyBufferedOutputStream extends FilterOutputStream {
- private UnsynchronizedByteArrayOutputStream buf = new UnsynchronizedByteArrayOutputStream();
+ private UnsyncByteArrayOutputStream buf = new UnsyncByteArrayOutputStream();
public FullyBufferedOutputStream(OutputStream out) {
super(out);
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncBufferedOutputStream.java Tue Oct 18 11:25:42 2016
@@ -1,94 +1,81 @@
-/**
- * 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
+/*
+ * 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
+ * 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.
+ * 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.xml.security.utils;
+import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
-/**
- * A class that buffers without synchronizing its methods
- * @author raul
- */
-public class UnsyncBufferedOutputStream extends OutputStream {
- static final int size = 8*1024;
-
- private int pointer = 0;
- private final OutputStream out;
+public class UnsyncBufferedOutputStream extends FilterOutputStream {
- private final byte[] buf;
+ protected byte[] buffer;
+ protected int count;
- /**
- * Creates a buffered output stream without synchronization
- * @param out the outputstream to buffer
- */
public UnsyncBufferedOutputStream(OutputStream out) {
- buf = new byte[size];
- this.out = out;
+ super(out);
+ buffer = new byte[8192];
}
- /** @inheritDoc */
- public void write(byte[] arg0) throws IOException {
- write(arg0, 0, arg0.length);
- }
-
- /** @inheritDoc */
- public void write(byte[] arg0, int arg1, int len) throws IOException {
- int newLen = pointer+len;
- if (newLen > size) {
- flushBuffer();
- if (len > size) {
- out.write(arg0, arg1,len);
- return;
- }
- newLen = len;
+ public UnsyncBufferedOutputStream(OutputStream out, int size) {
+ super(out);
+ if (size <= 0) {
+ throw new IllegalArgumentException("size must be > 0");
}
- System.arraycopy(arg0, arg1, buf, pointer, len);
- pointer = newLen;
+ buffer = new byte[size];
}
- private void flushBuffer() throws IOException {
- if (pointer > 0) {
- out.write(buf, 0, pointer);
- }
- pointer = 0;
-
+ @Override
+ public void flush() throws IOException {
+ flushInternal();
+ out.flush();
}
- /** @inheritDoc */
- public void write(int arg0) throws IOException {
- if (pointer >= size) {
- flushBuffer();
+ @Override
+ public void write(byte[] bytes, int offset, int length) throws IOException {
+ if (length >= buffer.length) {
+ flushInternal();
+ out.write(bytes, offset, length);
+ return;
}
- buf[pointer++] = (byte)arg0;
- }
+ // flush the internal buffer first if we have not enough space left
+ if (length >= (buffer.length - count)) {
+ flushInternal();
+ }
- /** @inheritDoc */
- public void flush() throws IOException {
- flushBuffer();
- out.flush();
+ // the length is always less than (internalBuffer.length - count) here so arraycopy is safe
+ System.arraycopy(bytes, offset, buffer, count, length);
+ count += length;
}
- /** @inheritDoc */
- public void close() throws IOException {
- flush();
- out.close();
+ @Override
+ public void write(int oneByte) throws IOException {
+ if (count == buffer.length) {
+ out.write(buffer, 0, count);
+ count = 0;
+ }
+ buffer[count++] = (byte) oneByte;
}
+ private void flushInternal() throws IOException {
+ if (count > 0) {
+ out.write(buffer, 0, count);
+ count = 0;
+ }
+ }
}
Copied: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayInputStream.java (from r1765231, santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayInputStream.java)
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayInputStream.java?p2=santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayInputStream.java&p1=santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayInputStream.java&r1=1765231&r2=1765415&rev=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/stax/impl/util/UnsynchronizedByteArrayInputStream.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayInputStream.java Tue Oct 18 11:25:42 2016
@@ -15,7 +15,7 @@
* limitations under the License.
*/
-package org.apache.xml.security.stax.impl.util;
+package org.apache.xml.security.utils;
import java.io.IOException;
import java.io.InputStream;
@@ -23,9 +23,9 @@ import java.io.InputStream;
/**
* A specialized {@link InputStream } for reading the contents of a byte array.
*
- * @see UnsynchronizedByteArrayOutputStream
+ * @see UnsyncByteArrayOutputStream
*/
-public class UnsynchronizedByteArrayInputStream extends InputStream {
+public class UnsyncByteArrayInputStream extends InputStream {
/**
* The {@code byte} array containing the bytes to stream over.
*/
@@ -55,7 +55,7 @@ public class UnsynchronizedByteArrayInpu
* @param buf
* the byte array to stream over.
*/
- public UnsynchronizedByteArrayInputStream(byte buf[]) {
+ public UnsyncByteArrayInputStream(byte buf[]) {
this.mark = 0;
this.buf = buf;
this.count = buf.length;
@@ -73,7 +73,7 @@ public class UnsynchronizedByteArrayInpu
* @param length
* the number of bytes available for streaming.
*/
- public UnsynchronizedByteArrayInputStream(byte buf[], int offset, int length) {
+ public UnsyncByteArrayInputStream(byte buf[], int offset, int length) {
this.buf = buf;
pos = offset;
mark = offset;
Modified: santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java
URL: http://svn.apache.org/viewvc/santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java?rev=1765415&r1=1765414&r2=1765415&view=diff
==============================================================================
--- santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java (original)
+++ santuario/xml-security-java/trunk/src/main/java/org/apache/xml/security/utils/UnsyncByteArrayOutputStream.java Tue Oct 18 11:25:42 2016
@@ -1,99 +1,195 @@
-/**
- * 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
+/*
+ * 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
+ * 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.
+ * 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.xml.security.utils;
+import java.io.IOException;
import java.io.OutputStream;
+import java.io.UnsupportedEncodingException;
-/**
- * A simple Unsynced ByteArrayOutputStream
- * @author raul
- *
- */
-public class UnsyncByteArrayOutputStream extends OutputStream {
-
- private static final int INITIAL_SIZE = 8192;
-
- private byte[] buf;
- private int size = INITIAL_SIZE;
- private int pos = 0;
-
+public class UnsyncByteArrayOutputStream extends OutputStream {
+ /**
+ * The byte array containing the bytes written.
+ */
+ protected byte[] buf;
+
+ /**
+ * The number of bytes written.
+ */
+ protected int count;
+
+ /**
+ * Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
+ * If more than 32 bytes are written to this instance, the underlying byte
+ * array will expand.
+ */
public UnsyncByteArrayOutputStream() {
- buf = new byte[INITIAL_SIZE];
- }
-
- public void write(byte[] arg0) {
- if ((Integer.MAX_VALUE - pos) < arg0.length) {
- throw new OutOfMemoryError();
- }
- int newPos = pos + arg0.length;
- if (newPos > size) {
- expandSize(newPos);
- }
- System.arraycopy(arg0, 0, buf, pos, arg0.length);
- pos = newPos;
- }
-
- public void write(byte[] arg0, int arg1, int arg2) {
- if ((Integer.MAX_VALUE - pos) < arg2) {
- throw new OutOfMemoryError();
- }
- int newPos = pos + arg2;
- if (newPos > size) {
- expandSize(newPos);
- }
- System.arraycopy(arg0, arg1, buf, pos, arg2);
- pos = newPos;
- }
-
- public void write(int arg0) {
- if (Integer.MAX_VALUE - pos == 0) {
- throw new OutOfMemoryError();
- }
- int newPos = pos + 1;
- if (newPos > size) {
- expandSize(newPos);
- }
- buf[pos++] = (byte)arg0;
- }
-
- public byte[] toByteArray() {
- byte result[] = new byte[pos];
- System.arraycopy(buf, 0, result, 0, pos);
- return result;
+ super();
+ buf = new byte[32];
}
+ /**
+ * Constructs a new {@code ByteArrayOutputStream} with a default size of
+ * {@code size} bytes. If more than {@code size} bytes are written to this
+ * instance, the underlying byte array will expand.
+ *
+ * @param size
+ * initial size for the underlying byte array, must be
+ * non-negative.
+ * @throws IllegalArgumentException
+ * if {@code size} < 0.
+ */
+ public UnsyncByteArrayOutputStream(int size) {
+ super();
+ if (size < 0) {
+ throw new IllegalArgumentException("size must be >= 0");
+ }
+ buf = new byte[size];
+ }
+
+ private void expand(int i) {
+ /* Can the buffer handle @i more bytes, if not expand it */
+ if (count + i <= buf.length) {
+ return;
+ }
+
+ byte[] newbuf = new byte[(count + i) << 1];
+ System.arraycopy(buf, 0, newbuf, 0, count);
+ buf = newbuf;
+ }
+
+ /**
+ * Resets this stream to the beginning of the underlying byte array. All
+ * subsequent writes will overwrite any bytes previously stored in this
+ * stream.
+ */
public void reset() {
- pos = 0;
+ count = 0;
}
- private void expandSize(int newPos) {
- int newSize = size;
- while (newPos > newSize) {
- newSize = newSize << 1;
- // Deal with overflow
- if (newSize < 0) {
- newSize = Integer.MAX_VALUE;
- }
- }
- byte newBuf[] = new byte[newSize];
- System.arraycopy(buf, 0, newBuf, 0, pos);
- buf = newBuf;
- size = newSize;
+ /**
+ * Returns the total number of bytes written to this stream so far.
+ *
+ * @return the number of bytes written to this stream.
+ */
+ public int size() {
+ return count;
+ }
+
+ /**
+ * Returns the contents of this ByteArrayOutputStream as a byte array. Any
+ * changes made to the receiver after returning will not be reflected in the
+ * byte array returned to the caller.
+ *
+ * @return this stream's current contents as a byte array.
+ */
+ public byte[] toByteArray() {
+ byte[] newArray = new byte[count];
+ System.arraycopy(buf, 0, newArray, 0, count);
+ return newArray;
+ }
+
+ /**
+ * Returns the contents of this ByteArrayOutputStream as a string. Any
+ * changes made to the receiver after returning will not be reflected in the
+ * string returned to the caller.
+ *
+ * @return this stream's current contents as a string.
+ */
+
+ @Override
+ public String toString() {
+ return new String(buf, 0, count);
+ }
+
+ /**
+ * Returns the contents of this ByteArrayOutputStream as a string converted
+ * according to the encoding declared in {@code enc}.
+ *
+ * @param enc
+ * a string representing the encoding to use when translating
+ * this stream to a string.
+ * @return this stream's current contents as an encoded string.
+ * @throws UnsupportedEncodingException
+ * if the provided encoding is not supported.
+ */
+ public String toString(String enc) throws UnsupportedEncodingException {
+ return new String(buf, 0, count, enc);
+ }
+
+ /**
+ * Writes {@code count} bytes from the byte array {@code buffer} starting at
+ * offset {@code index} to this stream.
+ *
+ * @param buffer
+ * the buffer to be written.
+ * @param offset
+ * the initial position in {@code buffer} to retrieve bytes.
+ * @param len
+ * the number of bytes of {@code buffer} to write.
+ * @throws NullPointerException
+ * if {@code buffer} is {@code null}.
+ * @throws IndexOutOfBoundsException
+ * if {@code offset < 0} or {@code len < 0}, or if
+ * {@code offset + len} is greater than the length of
+ * {@code buffer}.
+ */
+ @Override
+ public void write(byte[] buffer, int offset, int len) {
+ // avoid int overflow
+ if (offset < 0 || offset > buffer.length || len < 0
+ || len > buffer.length - offset) {
+ throw new IndexOutOfBoundsException();
+ }
+ if (len == 0) {
+ return;
+ }
+
+ /* Expand if necessary */
+ expand(len);
+ System.arraycopy(buffer, offset, buf, this.count, len);
+ this.count += len;
+ }
+
+ /**
+ * Writes the specified byte {@code oneByte} to the OutputStream. Only the
+ * low order byte of {@code oneByte} is written.
+ *
+ * @param oneByte
+ * the byte to be written.
+ */
+ @Override
+ public void write(int oneByte) {
+ if (count == buf.length) {
+ expand(1);
+ }
+ buf[count++] = (byte) oneByte;
+ }
+
+ /**
+ * Takes the contents of this stream and writes it to the output stream
+ * {@code out}.
+ *
+ * @param out
+ * an OutputStream on which to write the contents of this stream.
+ * @throws IOException
+ * if an error occurs while writing to {@code out}.
+ */
+ public void writeTo(OutputStream out) throws IOException {
+ out.write(buf, 0, count);
}
}