mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-29 11:15:51 +00:00
Simplication
This commit is contained in:
parent
1a8823966a
commit
17365cbb9b
1 changed files with 13 additions and 26 deletions
|
@ -1632,43 +1632,30 @@ public class Helper {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy(File src, File dst) throws IOException {
|
static void copy(File src, File dst) throws IOException {
|
||||||
try (InputStream in = new FileInputStream(src)) {
|
try (InputStream is = new FileInputStream(src)) {
|
||||||
try (FileOutputStream out = new FileOutputStream(dst)) {
|
try (FileOutputStream os = new FileOutputStream(dst)) {
|
||||||
copy(in, out);
|
copy(is, os);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void copy(InputStream in, OutputStream out) throws IOException {
|
static long copy(InputStream is, OutputStream os) throws IOException {
|
||||||
|
long size = 0;
|
||||||
byte[] buf = new byte[BUFFER_SIZE];
|
byte[] buf = new byte[BUFFER_SIZE];
|
||||||
int len;
|
int len;
|
||||||
while ((len = in.read(buf)) > 0)
|
while ((len = is.read(buf)) > 0) {
|
||||||
out.write(buf, 0, len);
|
size += len;
|
||||||
|
os.write(buf, 0, len);
|
||||||
|
}
|
||||||
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long copy(Context context, Uri uri, File file) throws IOException {
|
static long copy(Context context, Uri uri, File file) throws IOException {
|
||||||
long size = 0;
|
try (InputStream is = context.getContentResolver().openInputStream(uri)) {
|
||||||
InputStream is = null;
|
try (OutputStream os = new FileOutputStream(file)) {
|
||||||
OutputStream os = null;
|
return copy(is, os);
|
||||||
try {
|
|
||||||
is = context.getContentResolver().openInputStream(uri);
|
|
||||||
os = new FileOutputStream(file);
|
|
||||||
|
|
||||||
byte[] buffer = new byte[Helper.BUFFER_SIZE];
|
|
||||||
for (int len = is.read(buffer); len != -1; len = is.read(buffer)) {
|
|
||||||
size += len;
|
|
||||||
os.write(buffer, 0, len);
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (is != null)
|
|
||||||
is.close();
|
|
||||||
} finally {
|
|
||||||
if (os != null)
|
|
||||||
os.close();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return size;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static long getAvailableStorageSpace() {
|
static long getAvailableStorageSpace() {
|
||||||
|
|
Loading…
Reference in a new issue