Skip to content

Commit

Permalink
undo removing unused method to support legacy projects
Browse files Browse the repository at this point in the history
  • Loading branch information
유예본(Yebon You)/Platform Engineering팀/11ST authored and yaboong committed Nov 23, 2021
1 parent a17a9d3 commit cd39462
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public static int copy(InputStream in, OutputStream out) throws IOException {
int count = (int) in.transferTo(out);
out.flush();
return count;
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,29 @@ public static void copy(String in, Charset charset, OutputStream out) throws IOE
writer.flush();
}

/**
* Copy the contents of the given InputStream to the given OutputStream.
* <p>Leaves both streams open when done.
* @param in the InputStream to copy from
* @param out the OutputStream to copy to
* @return the number of bytes copied
* @throws IOException in case of I/O errors
*/
public static int copy(InputStream in, OutputStream out) throws IOException {
Assert.notNull(in, "No InputStream specified");
Assert.notNull(out, "No OutputStream specified");

int byteCount = 0;
byte[] buffer = new byte[BUFFER_SIZE];
int bytesRead;
while ((bytesRead = in.read(buffer)) != -1) {
out.write(buffer, 0, bytesRead);
byteCount += bytesRead;
}
out.flush();
return byteCount;
}

/**
* Copy a range of content of the given InputStream to the given OutputStream.
* <p>If the specified range exceeds the length of the InputStream, this copies
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ void copyString() throws Exception {
assertThat(out.toByteArray()).isEqualTo(string.getBytes(charset));
}

@Test
void copyStream() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
StreamUtils.copy(new ByteArrayInputStream(bytes), out);
assertThat(out.toByteArray()).isEqualTo(bytes);
}

@Test
void copyRange() throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.springframework.http.converter;

import java.io.ByteArrayOutputStream;
import java.io.IOException;

import org.springframework.http.HttpInputMessage;
Expand Down

0 comments on commit cd39462

Please sign in to comment.