Add static Util.EMPTY_BYTE_ARRAY
This prevents repeated instantiation of empty arrays. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=211941723
This commit is contained in:
parent
aa7134d538
commit
77a529f0ed
@ -27,6 +27,7 @@ import com.google.android.exoplayer2.upstream.DataSpec;
|
|||||||
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
import com.google.android.exoplayer2.upstream.HttpDataSource;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
import com.google.android.exoplayer2.util.Predicate;
|
import com.google.android.exoplayer2.util.Predicate;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
@ -301,7 +302,7 @@ public class OkHttpDataSource extends BaseDataSource implements HttpDataSource {
|
|||||||
requestBody = RequestBody.create(null, dataSpec.httpBody);
|
requestBody = RequestBody.create(null, dataSpec.httpBody);
|
||||||
} else if (dataSpec.httpMethod == DataSpec.HTTP_METHOD_POST) {
|
} else if (dataSpec.httpMethod == DataSpec.HTTP_METHOD_POST) {
|
||||||
// OkHttp requires a non-null body for POST requests.
|
// OkHttp requires a non-null body for POST requests.
|
||||||
requestBody = RequestBody.create(null, new byte[0]);
|
requestBody = RequestBody.create(null, Util.EMPTY_BYTE_ARRAY);
|
||||||
}
|
}
|
||||||
builder.method(dataSpec.getHttpMethodString(), requestBody);
|
builder.method(dataSpec.getHttpMethodString(), requestBody);
|
||||||
return builder.build();
|
return builder.build();
|
||||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.audio;
|
|||||||
import android.support.annotation.IntDef;
|
import android.support.annotation.IntDef;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.Format;
|
import com.google.android.exoplayer2.Format;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.lang.annotation.Retention;
|
import java.lang.annotation.Retention;
|
||||||
import java.lang.annotation.RetentionPolicy;
|
import java.lang.annotation.RetentionPolicy;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -102,8 +103,8 @@ public final class SilenceSkippingAudioProcessor implements AudioProcessor {
|
|||||||
outputBuffer = EMPTY_BUFFER;
|
outputBuffer = EMPTY_BUFFER;
|
||||||
channelCount = Format.NO_VALUE;
|
channelCount = Format.NO_VALUE;
|
||||||
sampleRateHz = Format.NO_VALUE;
|
sampleRateHz = Format.NO_VALUE;
|
||||||
maybeSilenceBuffer = new byte[0];
|
maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
paddingBuffer = new byte[0];
|
paddingBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -234,8 +235,8 @@ public final class SilenceSkippingAudioProcessor implements AudioProcessor {
|
|||||||
channelCount = Format.NO_VALUE;
|
channelCount = Format.NO_VALUE;
|
||||||
sampleRateHz = Format.NO_VALUE;
|
sampleRateHz = Format.NO_VALUE;
|
||||||
paddingSize = 0;
|
paddingSize = 0;
|
||||||
maybeSilenceBuffer = new byte[0];
|
maybeSilenceBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
paddingBuffer = new byte[0];
|
paddingBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Internal methods.
|
// Internal methods.
|
||||||
|
@ -44,7 +44,7 @@ import java.nio.ByteOrder;
|
|||||||
outputBuffer = EMPTY_BUFFER;
|
outputBuffer = EMPTY_BUFFER;
|
||||||
channelCount = Format.NO_VALUE;
|
channelCount = Format.NO_VALUE;
|
||||||
sampleRateHz = Format.NO_VALUE;
|
sampleRateHz = Format.NO_VALUE;
|
||||||
endBuffer = new byte[0];
|
endBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -180,7 +180,7 @@ import java.nio.ByteOrder;
|
|||||||
buffer = EMPTY_BUFFER;
|
buffer = EMPTY_BUFFER;
|
||||||
channelCount = Format.NO_VALUE;
|
channelCount = Format.NO_VALUE;
|
||||||
sampleRateHz = Format.NO_VALUE;
|
sampleRateHz = Format.NO_VALUE;
|
||||||
endBuffer = new byte[0];
|
endBuffer = Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ public final class HttpMediaDrmCallback implements MediaDrmCallback {
|
|||||||
public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
|
public byte[] executeProvisionRequest(UUID uuid, ProvisionRequest request) throws IOException {
|
||||||
String url =
|
String url =
|
||||||
request.getDefaultUrl() + "&signedRequest=" + Util.fromUtf8Bytes(request.getData());
|
request.getDefaultUrl() + "&signedRequest=" + Util.fromUtf8Bytes(request.getData());
|
||||||
return executePost(dataSourceFactory, url, new byte[0], null);
|
return executePost(dataSourceFactory, url, Util.EMPTY_BYTE_ARRAY, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -544,7 +544,7 @@ public final class TsExtractor implements Extractor {
|
|||||||
if (mode == MODE_HLS && id3Reader == null) {
|
if (mode == MODE_HLS && id3Reader == null) {
|
||||||
// Setup an ID3 track regardless of whether there's a corresponding entry, in case one
|
// Setup an ID3 track regardless of whether there's a corresponding entry, in case one
|
||||||
// appears intermittently during playback. See [Internal: b/20261500].
|
// appears intermittently during playback. See [Internal: b/20261500].
|
||||||
EsInfo dummyEsInfo = new EsInfo(TS_STREAM_TYPE_ID3, null, null, new byte[0]);
|
EsInfo dummyEsInfo = new EsInfo(TS_STREAM_TYPE_ID3, null, null, Util.EMPTY_BYTE_ARRAY);
|
||||||
id3Reader = payloadReaderFactory.createPayloadReader(TS_STREAM_TYPE_ID3, dummyEsInfo);
|
id3Reader = payloadReaderFactory.createPayloadReader(TS_STREAM_TYPE_ID3, dummyEsInfo);
|
||||||
id3Reader.init(timestampAdjuster, output,
|
id3Reader.init(timestampAdjuster, output,
|
||||||
new TrackIdGenerator(programNumber, TS_STREAM_TYPE_ID3, MAX_PID_PLUS_ONE));
|
new TrackIdGenerator(programNumber, TS_STREAM_TYPE_ID3, MAX_PID_PLUS_ONE));
|
||||||
|
@ -759,7 +759,7 @@ public final class Id3Decoder implements MetadataDecoder {
|
|||||||
private static byte[] copyOfRangeIfValid(byte[] data, int from, int to) {
|
private static byte[] copyOfRangeIfValid(byte[] data, int from, int to) {
|
||||||
if (to <= from) {
|
if (to <= from) {
|
||||||
// Invalid or zero length range.
|
// Invalid or zero length range.
|
||||||
return new byte[0];
|
return Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
return Arrays.copyOfRange(data, from, to);
|
return Arrays.copyOfRange(data, from, to);
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@ package com.google.android.exoplayer2.offline;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
import com.google.android.exoplayer2.util.Assertions;
|
import com.google.android.exoplayer2.util.Assertions;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.DataInputStream;
|
import java.io.DataInputStream;
|
||||||
import java.io.DataOutputStream;
|
import java.io.DataOutputStream;
|
||||||
@ -157,7 +158,7 @@ public abstract class DownloadAction {
|
|||||||
this.version = version;
|
this.version = version;
|
||||||
this.uri = uri;
|
this.uri = uri;
|
||||||
this.isRemoveAction = isRemoveAction;
|
this.isRemoveAction = isRemoveAction;
|
||||||
this.data = data != null ? data : new byte[0];
|
this.data = data != null ? data : Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Serializes itself into a byte array. */
|
/** Serializes itself into a byte array. */
|
||||||
|
@ -111,6 +111,9 @@ public final class Util {
|
|||||||
public static final String DEVICE_DEBUG_INFO = DEVICE + ", " + MODEL + ", " + MANUFACTURER + ", "
|
public static final String DEVICE_DEBUG_INFO = DEVICE + ", " + MODEL + ", " + MANUFACTURER + ", "
|
||||||
+ SDK_INT;
|
+ SDK_INT;
|
||||||
|
|
||||||
|
/** An empty byte array. */
|
||||||
|
public static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
|
||||||
|
|
||||||
private static final String TAG = "Util";
|
private static final String TAG = "Util";
|
||||||
private static final Pattern XS_DATE_TIME_PATTERN = Pattern.compile(
|
private static final Pattern XS_DATE_TIME_PATTERN = Pattern.compile(
|
||||||
"(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)[Tt]"
|
"(\\d\\d\\d\\d)\\-(\\d\\d)\\-(\\d\\d)[Tt]"
|
||||||
|
@ -20,6 +20,7 @@ import static com.google.common.truth.Truth.assertThat;
|
|||||||
import android.util.SparseBooleanArray;
|
import android.util.SparseBooleanArray;
|
||||||
import com.google.android.exoplayer2.C;
|
import com.google.android.exoplayer2.C;
|
||||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -255,7 +256,7 @@ public final class FakeExtractorInput implements ExtractorInput {
|
|||||||
private boolean simulateIOErrors;
|
private boolean simulateIOErrors;
|
||||||
|
|
||||||
public Builder() {
|
public Builder() {
|
||||||
data = new byte[0];
|
data = Util.EMPTY_BYTE_ARRAY;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder setData(byte[] data) {
|
public Builder setData(byte[] data) {
|
||||||
|
@ -22,6 +22,7 @@ import com.google.android.exoplayer2.Format;
|
|||||||
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
import com.google.android.exoplayer2.extractor.ExtractorInput;
|
||||||
import com.google.android.exoplayer2.extractor.TrackOutput;
|
import com.google.android.exoplayer2.extractor.TrackOutput;
|
||||||
import com.google.android.exoplayer2.util.ParsableByteArray;
|
import com.google.android.exoplayer2.util.ParsableByteArray;
|
||||||
|
import com.google.android.exoplayer2.util.Util;
|
||||||
import java.io.EOFException;
|
import java.io.EOFException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -44,7 +45,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
|||||||
public Format format;
|
public Format format;
|
||||||
|
|
||||||
public FakeTrackOutput() {
|
public FakeTrackOutput() {
|
||||||
sampleData = new byte[0];
|
sampleData = Util.EMPTY_BYTE_ARRAY;
|
||||||
sampleTimesUs = new ArrayList<>();
|
sampleTimesUs = new ArrayList<>();
|
||||||
sampleFlags = new ArrayList<>();
|
sampleFlags = new ArrayList<>();
|
||||||
sampleStartOffsets = new ArrayList<>();
|
sampleStartOffsets = new ArrayList<>();
|
||||||
@ -53,7 +54,7 @@ public final class FakeTrackOutput implements TrackOutput, Dumper.Dumpable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
sampleData = new byte[0];
|
sampleData = Util.EMPTY_BYTE_ARRAY;
|
||||||
sampleTimesUs.clear();
|
sampleTimesUs.clear();
|
||||||
sampleFlags.clear();
|
sampleFlags.clear();
|
||||||
sampleStartOffsets.clear();
|
sampleStartOffsets.clear();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user