Support SAF properly
This commit is contained in:
parent
1e09a1768e
commit
0f75024e03
23 changed files with 451 additions and 311 deletions
|
|
@ -0,0 +1,48 @@
|
|||
package org.schabi.newpipe.streams.io;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class SharpInputStream extends InputStream {
|
||||
private final SharpStream stream;
|
||||
|
||||
public SharpInputStream(final SharpStream stream) throws IOException {
|
||||
if (!stream.canRead()) {
|
||||
throw new IOException("SharpStream is not readable");
|
||||
}
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read() throws IOException {
|
||||
return stream.read();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull final byte[] b) throws IOException {
|
||||
return stream.read(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int read(@NonNull final byte[] b, final int off, final int len) throws IOException {
|
||||
return stream.read(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long skip(final long n) throws IOException {
|
||||
return stream.skip(n);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int available() {
|
||||
final long res = stream.available();
|
||||
return res > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
package org.schabi.newpipe.streams.io;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
|
||||
public class SharpOutputStream extends OutputStream {
|
||||
private final SharpStream stream;
|
||||
|
||||
public SharpOutputStream(final SharpStream stream) throws IOException {
|
||||
if (!stream.canWrite()) {
|
||||
throw new IOException("SharpStream is not writable");
|
||||
}
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(final int b) throws IOException {
|
||||
stream.write((byte) b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NonNull final byte[] b) throws IOException {
|
||||
stream.write(b);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(@NonNull final byte[] b, final int off, final int len) throws IOException {
|
||||
stream.write(b, off, len);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() throws IOException {
|
||||
stream.flush();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,12 +1,13 @@
|
|||
package org.schabi.newpipe.streams.io;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.io.Flushable;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* Based on C#'s Stream class.
|
||||
*/
|
||||
public abstract class SharpStream implements Closeable {
|
||||
public abstract class SharpStream implements Closeable, Flushable {
|
||||
public abstract int read() throws IOException;
|
||||
|
||||
public abstract int read(byte[] buffer) throws IOException;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue