Fix image save

This commit is contained in:
tarsin committed 2023-01-17 08:20:57 +08:00
1 parent d4dc65a4ba
commit da87fb2551
7 files changed
+12 -73

No files matched your search

@@ -260,23 +260,23 @@ public final class SpiderDen {
e.printStackTrace();
}
return new OutputStreamPipe() {
@Override
public void obtain() {
}
private OutputStream os = null;
@Override
public void release() {
editor.commit();
}
@NonNull
@Override
public OutputStream open() throws IOException {
return new FileOutputStream(editor.getData().toFile());
if (os != null) IOUtils.closeQuietly(os);
os = new FileOutputStream(editor.getData().toFile());
return os;
}
@Override
public void close() {
editor.commit();
if (os != null) IOUtils.closeQuietly(os);
}
};
}
@@ -326,25 +326,24 @@ public final class SpiderDen {
var snapshot = sCache.get(key);
if (snapshot == null) return null;
return new InputStreamPipe() {
@Override
public void obtain() {
}
private InputStream is = null;
@Override
public void release() {
snapshot.close();
}
@NonNull
@Override
public InputStream open() throws IOException {
return new FileInputStream(snapshot.getData().toFile());
if (is != null) IOUtils.closeQuietly(is);
is = new FileInputStream(snapshot.getData().toFile());
return is;
}
@Override
public void close() {
snapshot.close();
if (is != null) IOUtils.closeQuietly(is);
}
};
}
@@ -584,7 +584,6 @@ public final class SpiderQueen implements Runnable {
OutputStream os = null;
try {
os = file.openOutputStream();
pipe.obtain();
IOUtils.copy(pipe.open(), os);
return true;
} catch (IOException e) {
@@ -610,8 +609,6 @@ public final class SpiderQueen implements Runnable {
OutputStream os = null;
try {
pipe.obtain();
// Get dst file
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
@@ -650,8 +647,6 @@ public final class SpiderQueen implements Runnable {
}
try {
pipe.obtain();
// Get dst file
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
@@ -1288,7 +1283,6 @@ public final class SpiderQueen implements Runnable {
long contentLength = responseBody.contentLength();
is = responseBody.byteStream();
osPipe.obtain();
OutputStream os = osPipe.open();
final byte[] data = new byte[1024 * 4];
@@ -1340,7 +1334,6 @@ public final class SpiderQueen implements Runnable {
}
// Check plain txt
isPipe.obtain();
InputStream inputStream = new BufferedInputStream(isPipe.open());
boolean isPlainTxt = true;
int j = 0;
@@ -1644,7 +1637,6 @@ public final class SpiderQueen implements Runnable {
String error = null;
InputStream is;
pipe.obtain();
try {
is = pipe.open();
} catch (IOException e) {
@@ -34,11 +34,6 @@ public class UniFileInputStreamPipe implements InputStreamPipe {
mFile = file;
}
@Override
public void obtain() {
// Empty
}
@Override
public void release() {
// Empty
@@ -34,11 +34,6 @@ public class UniFileOutputStreamPipe implements OutputStreamPipe {
mUniFile = uniFile;
}
@Override
public void obtain() {
// Empty
}
@Override
public void release() {
// Empty
@@ -21,32 +21,12 @@ import androidx.annotation.NonNull;
import java.io.IOException;
import java.io.InputStream;
/**
* A pipe to open {@code InputStream}
*/
public interface InputStreamPipe {
/**
* Obtain the {@code InputStreamPipe}.
* Call it before opening {@code InputStream}.
*/
void obtain();
/**
* Release the {@code InputStreamPipe}.
*/
void release();
/**
* Open {@code InputStream}
*
* @return the {@code InputStream}
*/
@NonNull
InputStream open() throws IOException;
/**
* Close the {@code InputStream} opened before.
*/
void close();
}
@@ -21,32 +21,12 @@ import androidx.annotation.NonNull;
import java.io.IOException;
import java.io.OutputStream;
/**
* A pipe to open {@code OutputStream}
*/
public interface OutputStreamPipe {
/**
* Obtain the {@code OutputStreamPipe}.
* Call it before opening {@code OutputStream}.
*/
void obtain();
/**
* Release the {@code OutputStreamPipe}.
*/
void release();
/**
* Open {@code OutputStream}
*
* @return the {@code OutputStream}
*/
@NonNull
OutputStream open() throws IOException;
/**
* Close the {@code OutputStream} opened before.
*/
void close();
}
@@ -50,8 +50,6 @@ public final class BitmapUtils {
public static Bitmap decodeStream(@NonNull InputStreamPipe isp, int maxWidth, int maxHeight,
int pixels, boolean checkMemory, boolean justCalc, int[] sampleSize) {
try {
isp.obtain();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(isp.open(), null, options);