Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
youfanx committed Aug 28, 2023
1 parent 44db463 commit 23df0fe
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions rxlib/src/main/java/org/rx/io/HybridStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
@Slf4j
public final class HybridStream extends IOStream implements Serializable {
private static final long serialVersionUID = 2137331266386948293L;

public static final int NON_MEMORY_SIZE = 0;
private final int maxMemorySize;
private final String tempFilePath;
private IOStream stream;
Expand Down Expand Up @@ -66,11 +68,10 @@ public HybridStream(int maxMemorySize, boolean directMemory) {
}

public HybridStream(int maxMemorySize, boolean directMemory, String tempFilePath) {
if ((this.maxMemorySize = maxMemorySize) > Constants.MAX_HEAP_BUF_SIZE) {
log.warn("maxMemorySize gt {}", Constants.MAX_HEAP_BUF_SIZE);
}
this.maxMemorySize = Math.min(maxMemorySize, Constants.MAX_HEAP_BUF_SIZE);
this.tempFilePath = tempFilePath;
stream = maxMemorySize <= 0 ? newFileStream() : new MemoryStream(maxMemorySize, directMemory);
//todo when memStream write len > MAX_HEAP_BUF_SIZE
stream = maxMemorySize <= NON_MEMORY_SIZE ? newFileStream() : new MemoryStream(maxMemorySize, directMemory);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion rxlib/src/main/java/org/rx/net/http/HttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public synchronized <T> T handle(BiFunc<InputStream, T> fn) {
}
try {
Long len = Reflects.changeType(response.header(HttpHeaderNames.CONTENT_LENGTH.toString()), Long.class);
stream = new HybridStream(len != null && len > Constants.MAX_HEAP_BUF_SIZE ? 0 : Constants.MAX_HEAP_BUF_SIZE, false);
stream = new HybridStream(len != null && len > Constants.MAX_HEAP_BUF_SIZE ? HybridStream.NON_MEMORY_SIZE : Constants.MAX_HEAP_BUF_SIZE, false);
stream.write(body.byteStream());
} finally {
body.close();
Expand Down

0 comments on commit 23df0fe

Please sign in to comment.