mirror of
https://gitee.com/zhangsken/AndroidIDE.git
synced 2026-10-16 07:49:44 +08:00
build(desugaring): enable desugaring for InputStream.transferTo(OutputStream) in JGit
This commit is contained in:
+15
-1
@@ -19,6 +19,7 @@ package com.itsaky.androidide.desugaring.core.java.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -119,10 +120,23 @@ public class DesugarInputStream {
|
||||
int n = 0;
|
||||
while (n < len) {
|
||||
int count = input.read(b, off + n, len - n);
|
||||
if (count < 0)
|
||||
if (count < 0) {
|
||||
break;
|
||||
}
|
||||
n += count;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public static long transferTo(InputStream in, OutputStream out) throws IOException {
|
||||
Objects.requireNonNull(out, "out");
|
||||
long transferred = 0;
|
||||
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
|
||||
int read;
|
||||
while ((read = in.read(buffer, 0, DEFAULT_BUFFER_SIZE)) >= 0) {
|
||||
out.write(buffer, 0, read);
|
||||
transferred += read;
|
||||
}
|
||||
return transferred;
|
||||
}
|
||||
}
|
||||
|
||||
+6
-1
@@ -17,6 +17,8 @@
|
||||
|
||||
package com.itsaky.androidide.desugaring.dsl
|
||||
|
||||
import java.io.Serializable
|
||||
|
||||
/**
|
||||
* Key for storing [ReplaceMethodInsnKey] instances in a map.
|
||||
*
|
||||
@@ -26,4 +28,7 @@ data class ReplaceMethodInsnKey(
|
||||
val className: String,
|
||||
val methodName: String,
|
||||
val methodDescriptor: String
|
||||
)
|
||||
) : Serializable {
|
||||
@JvmField
|
||||
val serialVersionUID = 1L
|
||||
}
|
||||
|
||||
+5
@@ -59,5 +59,10 @@ object JavaIOReplacements {
|
||||
InputStream::readAllBytes.javaMethod!!,
|
||||
DesugarInputStream::readAllBytes.javaMethod!!
|
||||
)
|
||||
|
||||
replaceMethod(
|
||||
InputStream::transferTo.javaMethod!!,
|
||||
DesugarInputStream::transferTo.javaMethod!!
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user