提交 540d8792 编写于 作者: J Juergen Hoeller

Fixed javadoc warnings and revised FastByteArrayOutputStream code style

上级 45a80fa3
......@@ -28,6 +28,7 @@ import java.security.NoSuchAlgorithmException;
* more comprehensive suite of digest utilities.
*
* @author Arjen Poutsma
* @author Craig Andrews
* @since 3.0
* @see org.apache.commons.codec.digest.DigestUtils
*/
......@@ -38,6 +39,7 @@ public abstract class DigestUtils {
private static final char[] HEX_CHARS =
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
/**
* Calculate the MD5 digest of the given bytes.
* @param bytes the bytes to calculate the digest over
......@@ -53,7 +55,7 @@ public abstract class DigestUtils {
* @return the digest
* @since 4.2
*/
public static byte[] md5Digest(InputStream inputStream) throws IOException{
public static byte[] md5Digest(InputStream inputStream) throws IOException {
return digest(MD5_ALGORITHM_NAME, inputStream);
}
......@@ -74,7 +76,7 @@ public abstract class DigestUtils {
* @return a hexadecimal digest string
* @since 4.2
*/
public static String md5DigestAsHex(InputStream inputStream) throws IOException{
public static String md5DigestAsHex(InputStream inputStream) throws IOException {
return digestAsHexString(MD5_ALGORITHM_NAME, inputStream);
}
......@@ -97,13 +99,14 @@ public abstract class DigestUtils {
* @return the given string builder
* @since 4.2
*/
public static StringBuilder appendMd5DigestAsHex(InputStream inputStream, StringBuilder builder) throws IOException{
public static StringBuilder appendMd5DigestAsHex(InputStream inputStream, StringBuilder builder) throws IOException {
return appendDigestAsHex(MD5_ALGORITHM_NAME, inputStream, builder);
}
/**
* Creates a new {@link MessageDigest} with the given algorithm. Necessary
* because {@code MessageDigest} is not thread-safe.
* Create a new {@link MessageDigest} with the given algorithm.
* Necessary because {@code MessageDigest} is not thread-safe.
*/
private static MessageDigest getDigest(String algorithm) {
try {
......@@ -118,12 +121,13 @@ public abstract class DigestUtils {
return getDigest(algorithm).digest(bytes);
}
private static byte[] digest(String algorithm, InputStream inputStream) throws IOException{
private static byte[] digest(String algorithm, InputStream inputStream) throws IOException {
MessageDigest messageDigest = getDigest(algorithm);
if(inputStream instanceof UpdateMessageDigestInputStream){
if (inputStream instanceof UpdateMessageDigestInputStream){
((UpdateMessageDigestInputStream) inputStream).updateMessageDigest(messageDigest);
return messageDigest.digest();
}else{
}
else{
return messageDigest.digest(StreamUtils.copyToByteArray(inputStream));
}
}
......@@ -133,7 +137,7 @@ public abstract class DigestUtils {
return new String(hexDigest);
}
private static String digestAsHexString(String algorithm, InputStream inputStream) throws IOException{
private static String digestAsHexString(String algorithm, InputStream inputStream) throws IOException {
char[] hexDigest = digestAsHexChars(algorithm, inputStream);
return new String(hexDigest);
}
......@@ -143,7 +147,9 @@ public abstract class DigestUtils {
return builder.append(hexDigest);
}
private static StringBuilder appendDigestAsHex(String algorithm, InputStream inputStream, StringBuilder builder) throws IOException{
private static StringBuilder appendDigestAsHex(String algorithm, InputStream inputStream, StringBuilder builder)
throws IOException {
char[] hexDigest = digestAsHexChars(algorithm, inputStream);
return builder.append(hexDigest);
}
......@@ -153,7 +159,7 @@ public abstract class DigestUtils {
return encodeHex(digest);
}
private static char[] digestAsHexChars(String algorithm, InputStream inputStream) throws IOException{
private static char[] digestAsHexChars(String algorithm, InputStream inputStream) throws IOException {
byte[] digest = digest(algorithm, inputStream);
return encodeHex(digest);
}
......
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -27,6 +27,11 @@ import java.io.ByteArrayOutputStream;
* <li>has a higher initial capacity (256) by default</li>
* </ul>
*
* <p>As of 4.2, this class has been superseded by {@link FastByteArrayOutputStream}
* for Spring's internal use where no assignability to {@link ByteArrayOutputStream}
* is needed (since {@link FastByteArrayOutputStream} is more efficient with buffer
* resize management but doesn't extend the standard {@link ByteArrayOutputStream}).
*
* @author Brian Clozel
* @author Juergen Hoeller
* @since 4.0.3
......@@ -38,7 +43,7 @@ public class ResizableByteArrayOutputStream extends ByteArrayOutputStream {
/**
* Create a new <code>ResizableByteArrayOutputStream</code>
* with the default initial capacity of 128 bytes.
* with the default initial capacity of 256 bytes.
*/
public ResizableByteArrayOutputStream() {
super(DEFAULT_INITIAL_CAPACITY);
......
......@@ -27,38 +27,37 @@ import java.security.MessageDigest;
* @author Craig Andrews
* @since 4.2
*/
public abstract class UpdateMessageDigestInputStream extends InputStream {
abstract class UpdateMessageDigestInputStream extends InputStream {
/**
* Update the message digest with the rest of the bytes in this stream
*
* <p>Using this method is more optimized since it avoids creating new byte arrays for each call.</p>
*
* Update the message digest with the rest of the bytes in this stream.
* <p>Using this method is more optimized since it avoids creating new
* byte arrays for each call.
* @param messageDigest The message digest to update
* @throws IOException
* @throws IOException when propagated from {@link #read()}
*/
public void updateMessageDigest(MessageDigest messageDigest) throws IOException{
public void updateMessageDigest(MessageDigest messageDigest) throws IOException {
int data;
while((data = read()) != -1){
messageDigest.update((byte)data);
while ((data = read()) != -1){
messageDigest.update((byte) data);
}
}
/**
* Update the message digest with the next len bytes in this stream
*
* <p>Using this method is more optimized since it avoids creating new byte arrays for each call.</p>
*
* Update the message digest with the next len bytes in this stream.
* <p>Using this method is more optimized since it avoids creating new
* byte arrays for each call.
* @param messageDigest The message digest to update
* @param len how many bytes to read from this stream and use to update the message digest
* @throws IOException
* @throws IOException when propagated from {@link #read()}
*/
public void updateMessageDigest(MessageDigest messageDigest, int len) throws IOException{
public void updateMessageDigest(MessageDigest messageDigest, int len) throws IOException {
int data;
int bytesRead = 0;
while(bytesRead < len && (data = read()) != -1){
messageDigest.update((byte)data);
while (bytesRead < len && (data = read()) != -1){
messageDigest.update((byte) data);
bytesRead++;
}
}
}
......@@ -31,30 +31,30 @@ public class ScriptStatementFailedException extends ScriptException {
/**
* Construct a new {@code ScriptStatementFailedException}.
* @param statement the actual SQL statement that failed
* @param statementNumber the statement number in the SQL script (i.e.,
* @param stmt the actual SQL statement that failed
* @param stmtNumber the statement number in the SQL script (i.e.,
* the nth statement present in the resource)
* @param resource the resource from which the SQL statement was read
* @param cause the underlying cause of the failure
*/
public ScriptStatementFailedException(String statement, int statementNumber, EncodedResource resource, Throwable cause) {
super(buildErrorMessage(statement, statementNumber, resource), cause);
public ScriptStatementFailedException(String stmt, int stmtNumber, EncodedResource resource, Throwable cause) {
super(buildErrorMessage(stmt, stmtNumber, resource), cause);
}
/**
* Build an error message for an SQL script execution failure, based on
* the supplied arguments.
* @param statement the actual SQL statement that failed
* @param statementNumber the statement number in the SQL script (i.e.,
* Build an error message for an SQL script execution failure,
* based on the supplied arguments.
* @param stmt the actual SQL statement that failed
* @param stmtNumber the statement number in the SQL script (i.e.,
* the n<sup>th</sup> statement present in the resource)
* @param encodedResource the resource from which the SQL statement was read
* @return an error message suitable for an exception's <em>detail message</em>
* or logging
* @since 4.2
*/
public static String buildErrorMessage(String statement, int statementNumber, EncodedResource encodedResource) {
public static String buildErrorMessage(String stmt, int stmtNumber, EncodedResource encodedResource) {
return String.format("Failed to execute SQL script statement #%s of %s: %s",
statementNumber, encodedResource, statement);
stmtNumber, encodedResource, stmt);
}
}
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -29,6 +29,7 @@ import org.springframework.web.util.HtmlUtils;
* context-param in {@code web.xml}) is used.
*
* @author Juergen Hoeller
* @author Brian Clozel
* @since 1.1
* @see #setHtmlEscape
* @see HtmlEscapeTag
......@@ -76,24 +77,26 @@ public abstract class HtmlEscapingAwareTag extends RequestContextAwareTag {
}
/**
* Return the applicable default for the use of response encoding with HTML escape for this tag.
* Return the applicable default for the use of response encoding with
* HTML escaping for this tag.
* <p>The default implementation checks the RequestContext's setting,
* falling back to {@code false} in case of no explicit default given.
* @see #getRequestContext()
* @since 4.1.2
* @see #getRequestContext()
*/
protected boolean isResponseEncodedHtmlEscape() {
return getRequestContext().isResponseEncodedHtmlEscape();
}
/**
* HTML encodes the given string, only if the htmlEscape setting is enabled.
* The response encoding will be taken into account if the responseEncodedHtmlEscape setting is enabled.
* @param content
* @return
* HTML-encodes the given String, only if the "htmlEscape" setting is enabled.
* <p>The response encoding will be taken into account if the
* "responseEncodedHtmlEscape" setting is enabled as well.
* @param content the String to escape
* @return the escaped String
* @since 4.1.2
* @see #isHtmlEscape()
* @see #isResponseEncodedHtmlEscape()
* @since 4.1.2
*/
protected String htmlEscape(String content) {
String out = content;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册