Skip to content

Commit dd7c6f8

Browse files
Merge AbstractBufferedEncoder base class into its only subclass OutputStreamEncoder.
After the prior cleanup, this is the last use of the base class left and we are unlikely to reuse the base class for another different type, so we can merge it in. PiperOrigin-RevId: 848198069
1 parent 232f409 commit dd7c6f8

File tree

1 file changed

+22
-24
lines changed

1 file changed

+22
-24
lines changed

java/core/src/main/java/com/google/protobuf/CodedOutputStream.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1682,14 +1682,28 @@ private void encode(String value) throws IOException {
16821682
}
16831683
}
16841684

1685-
/** Abstract base class for buffered encoders. */
1686-
private abstract static class AbstractBufferedEncoder extends CodedOutputStream {
1687-
final byte[] buffer;
1688-
final int limit;
1689-
int position;
1690-
int totalBytesWritten;
1691-
1692-
AbstractBufferedEncoder(int bufferSize) {
1685+
/**
1686+
* An encoder that writes into an OutputStream. This internally uses an array for buffering to
1687+
* improve efficiency.
1688+
*/
1689+
private static final class OutputStreamEncoder extends CodedOutputStream {
1690+
private final byte[] buffer;
1691+
private final int limit;
1692+
private int position;
1693+
private int totalBytesWritten;
1694+
1695+
/**
1696+
* An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal
1697+
* buffering to optimize writes to the {@link OutputStream}.
1698+
*/
1699+
private final OutputStream out;
1700+
1701+
OutputStreamEncoder(OutputStream out, int bufferSize) {
1702+
if (out == null) {
1703+
throw new NullPointerException("out");
1704+
}
1705+
this.out = out;
1706+
16931707
if (bufferSize < 0) {
16941708
throw new IllegalArgumentException("bufferSize must be >= 0");
16951709
}
@@ -1843,22 +1857,6 @@ final void bufferFixed64NoTag(long value) {
18431857
this.position = position;
18441858
totalBytesWritten += FIXED64_SIZE;
18451859
}
1846-
}
1847-
1848-
/**
1849-
* An {@link CodedOutputStream} that decorates an {@link OutputStream}. It performs internal
1850-
* buffering to optimize writes to the {@link OutputStream}.
1851-
*/
1852-
private static final class OutputStreamEncoder extends AbstractBufferedEncoder {
1853-
private final OutputStream out;
1854-
1855-
OutputStreamEncoder(OutputStream out, int bufferSize) {
1856-
super(bufferSize);
1857-
if (out == null) {
1858-
throw new NullPointerException("out");
1859-
}
1860-
this.out = out;
1861-
}
18621860

18631861
@Override
18641862
public void writeTag(final int fieldNumber, final int wireType) throws IOException {

0 commit comments

Comments
 (0)