checkstyle

* drop unused methods
* split blobs
* make no final parameters
This commit is contained in:
kapodamy 2020-04-08 12:08:01 -03:00
parent e4a4af34c5
commit ff9a1ebb1b
6 changed files with 1244 additions and 1316 deletions

View File

@ -1,262 +1,262 @@
package org.schabi.newpipe.streams; package org.schabi.newpipe.streams;
import org.schabi.newpipe.streams.io.SharpStream; import org.schabi.newpipe.streams.io.SharpStream;
import java.io.EOFException; import java.io.EOFException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
* @author kapodamy * @author kapodamy
*/ */
public class DataReader { public class DataReader {
public static final int SHORT_SIZE = 2; public static final int SHORT_SIZE = 2;
public static final int LONG_SIZE = 8; public static final int LONG_SIZE = 8;
public static final int INTEGER_SIZE = 4; public static final int INTEGER_SIZE = 4;
public static final int FLOAT_SIZE = 4; public static final int FLOAT_SIZE = 4;
private static final int BUFFER_SIZE = 128 * 1024; // 128 KiB private static final int BUFFER_SIZE = 128 * 1024; // 128 KiB
private long position = 0; private long position = 0;
private final SharpStream stream; private final SharpStream stream;
private InputStream view; private InputStream view;
private int viewSize; private int viewSize;
public DataReader(final SharpStream stream) { public DataReader(final SharpStream stream) {
this.stream = stream; this.stream = stream;
this.readOffset = this.readBuffer.length; this.readOffset = this.readBuffer.length;
} }
public long position() { public long position() {
return position; return position;
} }
public int read() throws IOException { public int read() throws IOException {
if (fillBuffer()) { if (fillBuffer()) {
return -1; return -1;
} }
position++; position++;
readCount--; readCount--;
return readBuffer[readOffset++] & 0xFF; return readBuffer[readOffset++] & 0xFF;
} }
public long skipBytes(long amount) throws IOException { public long skipBytes(long amount) throws IOException {
if (readCount < 0) { if (readCount < 0) {
return 0; return 0;
} else if (readCount == 0) { } else if (readCount == 0) {
amount = stream.skip(amount); amount = stream.skip(amount);
} else { } else {
if (readCount > amount) { if (readCount > amount) {
readCount -= (int) amount; readCount -= (int) amount;
readOffset += (int) amount; readOffset += (int) amount;
} else { } else {
amount = readCount + stream.skip(amount - readCount); amount = readCount + stream.skip(amount - readCount);
readCount = 0; readCount = 0;
readOffset = readBuffer.length; readOffset = readBuffer.length;
} }
} }
position += amount; position += amount;
return amount; return amount;
} }
public int readInt() throws IOException { public int readInt() throws IOException {
primitiveRead(INTEGER_SIZE); primitiveRead(INTEGER_SIZE);
return primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3]; return primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3];
} }
public long readUnsignedInt() throws IOException { public long readUnsignedInt() throws IOException {
long value = readInt(); long value = readInt();
return value & 0xffffffffL; return value & 0xffffffffL;
} }
public short readShort() throws IOException { public short readShort() throws IOException {
primitiveRead(SHORT_SIZE); primitiveRead(SHORT_SIZE);
return (short) (primitive[0] << 8 | primitive[1]); return (short) (primitive[0] << 8 | primitive[1]);
} }
public long readLong() throws IOException { public long readLong() throws IOException {
primitiveRead(LONG_SIZE); primitiveRead(LONG_SIZE);
long high = primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3]; long high = primitive[0] << 24 | primitive[1] << 16 | primitive[2] << 8 | primitive[3];
long low = primitive[4] << 24 | primitive[5] << 16 | primitive[6] << 8 | primitive[7]; long low = primitive[4] << 24 | primitive[5] << 16 | primitive[6] << 8 | primitive[7];
return high << 32 | low; return high << 32 | low;
} }
public int read(final byte[] buffer) throws IOException { public int read(byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length); return read(buffer, 0, buffer.length);
} }
public int read(final byte[] buffer, int offset, int count) throws IOException { public int read(byte[] buffer, int offset, int count) throws IOException {
if (readCount < 0) { if (readCount < 0) {
return -1; return -1;
} }
int total = 0; int total = 0;
if (count >= readBuffer.length) { if (count >= readBuffer.length) {
if (readCount > 0) { if (readCount > 0) {
System.arraycopy(readBuffer, readOffset, buffer, offset, readCount); System.arraycopy(readBuffer, readOffset, buffer, offset, readCount);
readOffset += readCount; readOffset += readCount;
offset += readCount; offset += readCount;
count -= readCount; count -= readCount;
total = readCount; total = readCount;
readCount = 0; readCount = 0;
} }
total += Math.max(stream.read(buffer, offset, count), 0); total += Math.max(stream.read(buffer, offset, count), 0);
} else { } else {
while (count > 0 && !fillBuffer()) { while (count > 0 && !fillBuffer()) {
int read = Math.min(readCount, count); int read = Math.min(readCount, count);
System.arraycopy(readBuffer, readOffset, buffer, offset, read); System.arraycopy(readBuffer, readOffset, buffer, offset, read);
readOffset += read; readOffset += read;
readCount -= read; readCount -= read;
offset += read; offset += read;
count -= read; count -= read;
total += read; total += read;
} }
} }
position += total; position += total;
return total; return total;
} }
public boolean available() { public boolean available() {
return readCount > 0 || stream.available() > 0; return readCount > 0 || stream.available() > 0;
} }
public void rewind() throws IOException { public void rewind() throws IOException {
stream.rewind(); stream.rewind();
if ((position - viewSize) > 0) { if ((position - viewSize) > 0) {
viewSize = 0; // drop view viewSize = 0; // drop view
} else { } else {
viewSize += position; viewSize += position;
} }
position = 0; position = 0;
readOffset = readBuffer.length; readOffset = readBuffer.length;
readCount = 0; readCount = 0;
} }
public boolean canRewind() { public boolean canRewind() {
return stream.canRewind(); return stream.canRewind();
} }
/** /**
* Wraps this instance of {@code DataReader} into {@code InputStream} * Wraps this instance of {@code DataReader} into {@code InputStream}
* object. Note: Any read in the {@code DataReader} will not modify * object. Note: Any read in the {@code DataReader} will not modify
* (decrease) the view size * (decrease) the view size
* *
* @param size the size of the view * @param size the size of the view
* @return the view * @return the view
*/ */
public InputStream getView(final int size) { public InputStream getView(final int size) {
if (view == null) { if (view == null) {
view = new InputStream() { view = new InputStream() {
@Override @Override
public int read() throws IOException { public int read() throws IOException {
if (viewSize < 1) { if (viewSize < 1) {
return -1; return -1;
} }
int res = DataReader.this.read(); int res = DataReader.this.read();
if (res > 0) { if (res > 0) {
viewSize--; viewSize--;
} }
return res; return res;
} }
@Override @Override
public int read(final byte[] buffer) throws IOException { public int read(final byte[] buffer) throws IOException {
return read(buffer, 0, buffer.length); return read(buffer, 0, buffer.length);
} }
@Override @Override
public int read(final byte[] buffer, final int offset, final int count) public int read(final byte[] buffer, final int offset, final int count)
throws IOException { throws IOException {
if (viewSize < 1) { if (viewSize < 1) {
return -1; return -1;
} }
int res = DataReader.this.read(buffer, offset, Math.min(viewSize, count)); int res = DataReader.this.read(buffer, offset, Math.min(viewSize, count));
viewSize -= res; viewSize -= res;
return res; return res;
} }
@Override @Override
public long skip(final long amount) throws IOException { public long skip(final long amount) throws IOException {
if (viewSize < 1) { if (viewSize < 1) {
return 0; return 0;
} }
int res = (int) DataReader.this.skipBytes(Math.min(amount, viewSize)); int res = (int) DataReader.this.skipBytes(Math.min(amount, viewSize));
viewSize -= res; viewSize -= res;
return res; return res;
} }
@Override @Override
public int available() { public int available() {
return viewSize; return viewSize;
} }
@Override @Override
public void close() { public void close() {
viewSize = 0; viewSize = 0;
} }
@Override @Override
public boolean markSupported() { public boolean markSupported() {
return false; return false;
} }
}; };
} }
viewSize = size; viewSize = size;
return view; return view;
} }
private final short[] primitive = new short[LONG_SIZE]; private final short[] primitive = new short[LONG_SIZE];
private void primitiveRead(final int amount) throws IOException { private void primitiveRead(final int amount) throws IOException {
byte[] buffer = new byte[amount]; byte[] buffer = new byte[amount];
int read = read(buffer, 0, amount); int read = read(buffer, 0, amount);
if (read != amount) { if (read != amount) {
throw new EOFException("Truncated stream, missing " throw new EOFException("Truncated stream, missing "
+ String.valueOf(amount - read) + " bytes"); + String.valueOf(amount - read) + " bytes");
} }
for (int i = 0; i < amount; i++) { for (int i = 0; i < amount; i++) {
// the "byte" data type in java is signed and is very annoying // the "byte" data type in java is signed and is very annoying
primitive[i] = (short) (buffer[i] & 0xFF); primitive[i] = (short) (buffer[i] & 0xFF);
} }
} }
private final byte[] readBuffer = new byte[BUFFER_SIZE]; private final byte[] readBuffer = new byte[BUFFER_SIZE];
private int readOffset; private int readOffset;
private int readCount; private int readCount;
private boolean fillBuffer() throws IOException { private boolean fillBuffer() throws IOException {
if (readCount < 0) { if (readCount < 0) {
return true; return true;
} }
if (readOffset >= readBuffer.length) { if (readOffset >= readBuffer.length) {
readCount = stream.read(readBuffer); readCount = stream.read(readBuffer);
if (readCount < 1) { if (readCount < 1) {
readCount = -1; readCount = -1;
return true; return true;
} }
readOffset = 0; readOffset = 0;
} }
return readCount < 1; return readCount < 1;
} }
} }

File diff suppressed because it is too large Load Diff

View File

@ -640,7 +640,7 @@ public class Mp4FromDashWriter {
return size; return size;
} }
private byte[] makeMdat(long refSize, final boolean is64) { private byte[] makeMdat(long refSize, boolean is64) {
if (is64) { if (is64) {
refSize += 16; refSize += 16;
} else { } else {
@ -674,8 +674,9 @@ public class Mp4FromDashWriter {
0x00, 0x01, 0x00, 0x00, 0x01, 0x00, // default volume and rate 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, // default volume and rate
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved values 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // reserved values
// default matrix // default matrix
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00,
0x40, 0x00, 0x00, 0x00 0x40, 0x00, 0x00, 0x00
}); });
auxWrite(new byte[24]); // predefined auxWrite(new byte[24]); // predefined
@ -717,12 +718,13 @@ public class Mp4FromDashWriter {
// udta/meta/ilst/©too // udta/meta/ilst/©too
auxWrite(new byte[]{ auxWrite(new byte[]{
0x00, 0x00, 0x00, 0x5C, 0x75, 0x64, 0x74, 0x61, 0x00, 0x00, 0x00, 0x54, 0x6D, 0x65, 0x74, 0x61, 0x00, 0x00, 0x00, 0x5C, 0x75, 0x64, 0x74, 0x61, 0x00, 0x00, 0x00, 0x54, 0x6D, 0x65,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x68, 0x64, 0x6C, 0x72, 0x00, 0x00, 0x00, 0x00, 0x74, 0x61, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x68, 0x64, 0x6C, 0x72,
0x00, 0x00, 0x00, 0x00, 0x6D, 0x64, 0x69, 0x72, 0x61, 0x70, 0x70, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6D, 0x64, 0x69, 0x72, 0x61, 0x70,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x27, 0x69, 0x6C, 0x73, 0x74, 0x00, 0x00, 0x00, 0x70, 0x6C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x1F, (byte) 0xA9, 0x74, 0x6F, 0x6F, 0x00, 0x00, 0x00, 0x17, 0x64, 0x61, 0x74, 0x61, 0x00, 0x00, 0x27, 0x69, 0x6C, 0x73, 0x74, 0x00, 0x00, 0x00,
0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x1F, (byte) 0xA9, 0x74, 0x6F, 0x6F, 0x00, 0x00, 0x00, 0x17, 0x64, 0x61, 0x74, 0x61,
0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
0x4E, 0x65, 0x77, 0x50, 0x69, 0x70, 0x65 // "NewPipe" binary string 0x4E, 0x65, 0x77, 0x50, 0x69, 0x70, 0x65 // "NewPipe" binary string
}); });
@ -759,7 +761,8 @@ public class Mp4FromDashWriter {
auxWrite(new byte[]{ auxWrite(new byte[]{
0x00, 0x00, 0x00, 0x24, 0x65, 0x64, 0x74, 0x73, // edts header 0x00, 0x00, 0x00, 0x24, 0x65, 0x64, 0x74, 0x73, // edts header
0x00, 0x00, 0x00, 0x1C, 0x65, 0x6C, 0x73, 0x74, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 // elst header 0x00, 0x00, 0x00, 0x1C, 0x65, 0x6C, 0x73, 0x74,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01 // elst header
}); });
int bMediaRate; int bMediaRate;
@ -845,14 +848,18 @@ public class Mp4FromDashWriter {
private byte[] makeHdlr(final Hdlr hdlr) { private byte[] makeHdlr(final Hdlr hdlr) {
ByteBuffer buffer = ByteBuffer.wrap(new byte[]{ ByteBuffer buffer = ByteBuffer.wrap(new byte[]{
0x00, 0x00, 0x00, 0x77, 0x68, 0x64, 0x6C, 0x72, // hdlr 0x00, 0x00, 0x00, 0x77, 0x68, 0x64, 0x6C, 0x72, // hdlr
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
// binary string "ISO Media file created in NewPipe (A libre lightweight streaming frontend for Android)." // binary string
0x49, 0x53, 0x4F, 0x20, 0x4D, 0x65, 0x64, 0x69, 0x61, 0x20, 0x66, 0x69, 0x6C, 0x65, 0x20, 0x63, // "ISO Media file created in NewPipe (
0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6E, 0x20, 0x4E, 0x65, 0x77, 0x50, 0x69, 0x70, // A libre lightweight streaming frontend for Android)."
0x65, 0x20, 0x28, 0x41, 0x20, 0x6C, 0x69, 0x62, 0x72, 0x65, 0x20, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x49, 0x53, 0x4F, 0x20, 0x4D, 0x65, 0x64, 0x69, 0x61, 0x20, 0x66, 0x69, 0x6C, 0x65,
0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x73, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x69, 0x6E, 0x67, 0x20, 0x63, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x20, 0x69, 0x6E, 0x20, 0x4E, 0x65,
0x20, 0x66, 0x72, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x64, 0x20, 0x66, 0x6F, 0x72, 0x20, 0x41, 0x6E, 0x77, 0x50, 0x69, 0x70, 0x65, 0x20, 0x28, 0x41, 0x20, 0x6C, 0x69, 0x62, 0x72, 0x65,
0x20, 0x6C, 0x69, 0x67, 0x68, 0x74, 0x77, 0x65, 0x69, 0x67, 0x68, 0x74, 0x20, 0x73,
0x74, 0x72, 0x65, 0x61, 0x6D, 0x69,0x6E, 0x67,
0x20, 0x66, 0x72, 0x6F, 0x6E, 0x74, 0x65, 0x6E, 0x64, 0x20, 0x66, 0x6F, 0x72, 0x20,
0x41, 0x6E,
0x64, 0x72, 0x6F, 0x69, 0x64, 0x29, 0x2E 0x64, 0x72, 0x6F, 0x69, 0x64, 0x29, 0x2E
}); });

View File

@ -289,11 +289,13 @@ public class OggFromWebMWriter implements Closeable {
/* /*
// whole file duration (not implemented) // whole file duration (not implemented)
0x44,// tag string size 0x44,// tag string size
0x55, 0x52, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x3D, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x55, 0x52, 0x41, 0x54, 0x49, 0x4F, 0x4E, 0x3D, 0x30,
0x30, 0x2E, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30, 0x30 0x30, 0x3A, 0x30, 0x30, 0x3A, 0x30, 0x30, 0x2E, 0x30,
0x30, 0x30, 0x30, 0x30, 0x30, 0x30
*/ */
0x0F, // tag string size 0x0F, // tag string size
0x00, 0x00, 0x00, 0x45, 0x4E, 0x43, 0x4F, 0x44, 0x45, 0x52, 0x3D, // "ENCODER=" binary string 0x00, 0x00, 0x00, 0x45, 0x4E, 0x43, 0x4F,
0x44, 0x45, 0x52, 0x3D, // "ENCODER=" binary string
0x4E, 0x65, 0x77, 0x50, 0x69, 0x70, 0x65, // "NewPipe" binary string 0x4E, 0x65, 0x77, 0x50, 0x69, 0x70, 0x65, // "NewPipe" binary string
0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ???????? 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 // ????????
}; };
@ -417,7 +419,7 @@ public class OggFromWebMWriter implements Closeable {
} }
} }
private int calcCrc32(int initialCrc, final byte[] buffer, final int size) { private int calcCrc32(int initialCrc, byte[] buffer, int size) {
for (int i = 0; i < size; i++) { for (int i = 0; i < size; i++) {
int reg = (initialCrc >>> 24) & 0xff; int reg = (initialCrc >>> 24) & 0xff;
initialCrc = (initialCrc << 8) ^ crc32Table[reg ^ (buffer[i] & 0xff)]; initialCrc = (initialCrc << 8) ^ crc32Table[reg ^ (buffer[i] & 0xff)];

View File

@ -102,10 +102,6 @@ public class WebMWriter implements Closeable {
return done; return done;
} }
public boolean isParsed() {
return parsed;
}
@Override @Override
public void close() { public void close() {
done = true; done = true;
@ -360,7 +356,7 @@ public class WebMWriter implements Closeable {
Block bloq = new Block(); Block bloq = new Block();
bloq.data = res.data; bloq.data = res.data;
bloq.dataSize = (int) res.dataSize; bloq.dataSize = res.dataSize;
bloq.trackNumber = internalTrackId; bloq.trackNumber = internalTrackId;
bloq.flags = res.flags; bloq.flags = res.flags;
bloq.absoluteTimecode = res.absoluteTimeCodeNs / DEFAULT_TIMECODE_SCALE; bloq.absoluteTimecode = res.absoluteTimeCodeNs / DEFAULT_TIMECODE_SCALE;
@ -728,7 +724,7 @@ public class WebMWriter implements Closeable {
return 0; return 0;
} }
class KeyFrame { static class KeyFrame {
KeyFrame(final long segment, final long cluster, final long block, final long timecode) { KeyFrame(final long segment, final long cluster, final long block, final long timecode) {
clusterPosition = cluster - segment; clusterPosition = cluster - segment;
relativePosition = (int) (block - cluster - CLUSTER_HEADER_SIZE); relativePosition = (int) (block - cluster - CLUSTER_HEADER_SIZE);
@ -740,7 +736,7 @@ public class WebMWriter implements Closeable {
final long duration; final long duration;
} }
class Block { static class Block {
InputStream data; InputStream data;
int trackNumber; int trackNumber;
byte flags; byte flags;
@ -759,7 +755,7 @@ public class WebMWriter implements Closeable {
} }
} }
class ClusterInfo { static class ClusterInfo {
long offset; long offset;
int size; int size;
} }

View File

@ -10,34 +10,4 @@
<suppress checks="FinalParameters" <suppress checks="FinalParameters"
files="InfoListAdapter.java" files="InfoListAdapter.java"
lines="253,325"/> lines="253,325"/>
<!-- org.schabi.newpipe.streams -->
<suppress checks="FinalParameters"
files="WebMWriter.java"
lines="423,595"/>
<suppress checks="LineLength"
files="WebMWriter.java"
lines="160,162"/>
<suppress checks="FinalParameters"
files="OggFromWebMWriter.java"
lines="378,420"/>
<suppress checks="LineLength"
files="OggFromWebMWriter.java"
lines="292,296"/>
<suppress checks="FinalParameters"
files="Mp4FromDashWriter.java"
lines="643"/>
<suppress checks="LineLength"
files="Mp4FromDashWriter.java"
lines="677,678,720-724,738,762,848,850-855"/>
<suppress checks="InnerAssignment"
files="Mp4DashReader.java"
lines="190"/>
<suppress checks="FinalParameters"
files="DataReader.java"
lines="46,93"/>
</suppressions> </suppressions>