Browse Source

SPR-17492: FastByteArrayOutputStream.read byte-to-int conversion

pull/2023/head
Vojtech Janota 6 years ago committed by Juergen Hoeller
parent
commit
12f168290d
  1. 2
      spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java
  2. 10
      spring-core/src/test/java/org/springframework/util/FastByteArrayOutputStreamTests.java

2
spring-core/src/main/java/org/springframework/util/FastByteArrayOutputStream.java

@ -367,7 +367,7 @@ public class FastByteArrayOutputStream extends OutputStream { @@ -367,7 +367,7 @@ public class FastByteArrayOutputStream extends OutputStream {
else {
if (this.nextIndexInCurrentBuffer < this.currentBufferLength) {
this.totalBytesRead++;
return this.currentBuffer[this.nextIndexInCurrentBuffer++];
return this.currentBuffer[this.nextIndexInCurrentBuffer++] & 0xFF;
}
else {
if (this.buffersIterator.hasNext()) {

10
spring-core/src/test/java/org/springframework/util/FastByteArrayOutputStreamTests.java

@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
package org.springframework.util;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
@ -137,6 +138,15 @@ public class FastByteArrayOutputStreamTests { @@ -137,6 +138,15 @@ public class FastByteArrayOutputStreamTests {
assertEquals(inputStream.read(), this.helloBytes[3]);
}
@Test
public void getInputStreamReadBytePromotion() throws Exception {
byte[] bytes = new byte[] { -1 };
this.os.write(bytes);
InputStream inputStream = this.os.getInputStream();
ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
assertEquals(bais.read(), inputStream.read());
}
@Test
public void getInputStreamReadAll() throws Exception {
this.os.write(this.helloBytes);

Loading…
Cancel
Save