You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2023/06/26 09:44:17 UTC
[tomcat] 03/05: Align with 9.0.x onwards
This is an automated email from the ASF dual-hosted git repository.
markt pushed a commit to branch 8.5.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit c3b02a10c2a984553647b2fea38f2b7364a86933
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Mon Jun 26 10:39:02 2023 +0100
Align with 9.0.x onwards
---
java/org/apache/tomcat/util/buf/AbstractChunk.java | 3 ++
java/org/apache/tomcat/util/buf/ByteChunk.java | 48 +++++++++++++++++++---
java/org/apache/tomcat/util/buf/CharChunk.java | 21 +++++++++-
3 files changed, 65 insertions(+), 7 deletions(-)
diff --git a/java/org/apache/tomcat/util/buf/AbstractChunk.java b/java/org/apache/tomcat/util/buf/AbstractChunk.java
index 7bd7001181..3e06362f5f 100644
--- a/java/org/apache/tomcat/util/buf/AbstractChunk.java
+++ b/java/org/apache/tomcat/util/buf/AbstractChunk.java
@@ -18,12 +18,15 @@ package org.apache.tomcat.util.buf;
import java.io.Serializable;
+import org.apache.tomcat.util.res.StringManager;
+
/**
* Base class for the *Chunk implementation to reduce duplication.
*/
public abstract class AbstractChunk implements Cloneable, Serializable {
private static final long serialVersionUID = 1L;
+ protected static final StringManager sm = StringManager.getManager(AbstractChunk.class);
/*
* JVMs may limit the maximum array size to slightly less than Integer.MAX_VALUE. On markt's desktop the limit is
diff --git a/java/org/apache/tomcat/util/buf/ByteChunk.java b/java/org/apache/tomcat/util/buf/ByteChunk.java
index 58b6a57794..1002d2fe49 100644
--- a/java/org/apache/tomcat/util/buf/ByteChunk.java
+++ b/java/org/apache/tomcat/util/buf/ByteChunk.java
@@ -26,8 +26,6 @@ import java.nio.charset.Charset;
import java.nio.charset.CodingErrorAction;
import java.nio.charset.StandardCharsets;
-import org.apache.tomcat.util.res.StringManager;
-
/*
* In a server it is very important to be able to operate on
* the original byte[] without converting everything to chars.
@@ -114,8 +112,6 @@ public final class ByteChunk extends AbstractChunk {
// --------------------
- private static final StringManager sm = StringManager.getManager(ByteChunk.class);
-
/**
* Default encoding used to convert to strings. It should be UTF8, as most standards seem to converge, but the
* servlet API requires 8859_1, and this object is used mostly for servlets.
@@ -387,15 +383,30 @@ public final class ByteChunk extends AbstractChunk {
// -------------------- Removing data from the buffer --------------------
+ /*
+ * @deprecated Use {@link #subtract()}. This method will be removed in Tomcat 10
+ */
+ @Deprecated
public int substract() throws IOException {
+ return subtract();
+ }
+
+ public int subtract() throws IOException {
if (checkEof()) {
return -1;
}
return buff[start++] & 0xFF;
}
-
+ /*
+ * @deprecated Use {@link #subtractB()}. This method will be removed in Tomcat 10
+ */
+ @Deprecated
public byte substractB() throws IOException {
+ return subtractB();
+ }
+
+ public byte subtractB() throws IOException {
if (checkEof()) {
return -1;
}
@@ -403,7 +414,15 @@ public final class ByteChunk extends AbstractChunk {
}
+ /*
+ * @deprecated Use {@link #subtract(byte[],int,int)}. This method will be removed in Tomcat 10
+ */
+ @Deprecated
public int substract(byte dest[], int off, int len) throws IOException {
+ return subtract(dest, off, len);
+ }
+
+ public int subtract(byte dest[], int off, int len) throws IOException {
if (checkEof()) {
return -1;
}
@@ -427,8 +446,27 @@ public final class ByteChunk extends AbstractChunk {
* @return an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached
*
* @throws IOException if an input or output exception has occurred
+ *
+ * @deprecated Use {@link #subtract(ByteBuffer)}. This method will be removed in Tomcat 10
*/
+ @Deprecated
public int substract(ByteBuffer to) throws IOException {
+ return subtract(to);
+ }
+
+
+ /**
+ * Transfers bytes from the buffer to the specified ByteBuffer. After the operation the position of the ByteBuffer
+ * will be returned to the one before the operation, the limit will be the position incremented by the number of the
+ * transfered bytes.
+ *
+ * @param to the ByteBuffer into which bytes are to be written.
+ *
+ * @return an integer specifying the actual number of bytes read, or -1 if the end of the stream is reached
+ *
+ * @throws IOException if an input or output exception has occurred
+ */
+ public int subtract(ByteBuffer to) throws IOException {
if (checkEof()) {
return -1;
}
diff --git a/java/org/apache/tomcat/util/buf/CharChunk.java b/java/org/apache/tomcat/util/buf/CharChunk.java
index 9b78408c24..a79e539440 100644
--- a/java/org/apache/tomcat/util/buf/CharChunk.java
+++ b/java/org/apache/tomcat/util/buf/CharChunk.java
@@ -289,7 +289,15 @@ public final class CharChunk extends AbstractChunk implements CharSequence {
// -------------------- Removing data from the buffer --------------------
+ /*
+ * @deprecated Use {@link #subtract()}. This method will be removed in Tomcat 10
+ */
+ @Deprecated
public int substract() throws IOException {
+ return subtract();
+ }
+
+ public int subtract() throws IOException {
if (checkEof()) {
return -1;
}
@@ -297,7 +305,15 @@ public final class CharChunk extends AbstractChunk implements CharSequence {
}
+ /*
+ * @deprecated Use {@link #subtract(char[],int,int)}. This method will be removed in Tomcat 10
+ */
+ @Deprecated
public int substract(char dest[], int off, int len) throws IOException {
+ return subtract(dest, off, len);
+ }
+
+ public int subtract(char dest[], int off, int len) throws IOException {
if (checkEof()) {
return -1;
}
@@ -334,7 +350,8 @@ public final class CharChunk extends AbstractChunk implements CharSequence {
public void flushBuffer() throws IOException {
// assert out!=null
if (out == null) {
- throw new IOException("Buffer overflow, no sink " + getLimit() + " " + buff.length);
+ throw new IOException(
+ sm.getString("chunk.overflow", Integer.valueOf(getLimit()), Integer.valueOf(buff.length)));
}
out.realWriteChars(buff, start, end - start);
end = start;
@@ -395,7 +412,7 @@ public final class CharChunk extends AbstractChunk implements CharSequence {
@Override
public String toString() {
- if (null == buff) {
+ if (isNull()) {
return null;
} else if (end - start == 0) {
return "";
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org