granularity level: instruction

		.class final Lcom/google/firebase/messaging/ByteStreams;
.super Ljava/lang/Object;
.source "ByteStreams.java"

.annotation system Ldalvik/annotation/MemberClasses;
value = {
Lcom/google/firebase/messaging/ByteStreams$LimitedInputStream;
}
.end annotation

.field private static final BUFFER_SIZE:I = 0x2000
.field private static final MAX_ARRAY_LEN:I = 0x7ffffff7
.field private static final TO_BYTE_ARRAY_DEQUE_SIZE:I = 0x14


.method private constructor <init>()V
	.locals 0

	invoke-direct {p0}, Ljava/lang/Object;-><init>()V
	return-void
.end method

.method private static combineBuffers(Ljava/util/Queue;I)[B
	.locals 6
	.annotation system Ldalvik/annotation/Signature;
	value = {
	"(",
	"Ljava/util/Queue<",
	"[B>;I)[B"
	}
	.end annotation

	invoke-interface {p0}, Ljava/util/Queue;->isEmpty()Z
	move-result v0
	const/4 v1, 0x0
	if-eqz v0, :cond_0
	new-array p0, v1, [B
	return-object p0
	:cond_0
	invoke-interface {p0}, Ljava/util/Queue;->remove()Ljava/lang/Object;
	move-result-object v0
	check-cast v0, [B
	array-length v2, v0
	if-ne v2, p1, :cond_1
	return-object v0
	:cond_1
	array-length v2, v0
	sub-int v2, p1, v2
	invoke-static {v0, p1}, Ljava/util/Arrays;->copyOf([BI)[B
	move-result-object v0
	:goto_0
	if-lez v2, :cond_2
	invoke-interface {p0}, Ljava/util/Queue;->remove()Ljava/lang/Object;
	move-result-object v3
	check-cast v3, [B
	array-length v4, v3
	invoke-static {v2, v4}, Ljava/lang/Math;->min(II)I
	move-result v4
	sub-int v5, p1, v2
	invoke-static {v3, v1, v0, v5, v4}, Ljava/lang/System;->arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V
	sub-int/2addr v2, v4
	goto :goto_0
	:cond_2
	return-object v0
.end method

.method static createBuffer()[B
	.locals 1

	const/16 v0, 0x2000
	new-array v0, v0, [B
	return-object v0
.end method

.method public static limit(Ljava/io/InputStream;J)Ljava/io/InputStream;
	.locals 1

	new-instance v0, Lcom/google/firebase/messaging/ByteStreams$LimitedInputStream;
	invoke-direct {v0, p0, p1, p2}, Lcom/google/firebase/messaging/ByteStreams$LimitedInputStream;-><init>(Ljava/io/InputStream;J)V
	return-object v0
.end method

.method private static saturatedCast(J)I
	.locals 3

	const-wide/32 v0, 0x7fffffff
	cmp-long v2, p0, v0
	if-lez v2, :cond_0
	const p0, 0x7fffffff
	return p0
	:cond_0
	const-wide/32 v0, -0x80000000
	cmp-long v2, p0, v0
	if-gez v2, :cond_1
	const/high16 p0, -0x80000000
	return p0
	:cond_1
	long-to-int p1, p0
	return p1
.end method

.method public static toByteArray(Ljava/io/InputStream;)[B
	.locals 2
	.annotation system Ldalvik/annotation/Throws;
	value = {
	Ljava/io/IOException;
	}
	.end annotation

	new-instance v0, Ljava/util/ArrayDeque;
	const/16 v1, 0x14
	invoke-direct {v0, v1}, Ljava/util/ArrayDeque;-><init>(I)V
	const/4 v1, 0x0
	invoke-static {p0, v0, v1}, Lcom/google/firebase/messaging/ByteStreams;->toByteArrayInternal(Ljava/io/InputStream;Ljava/util/Queue;I)[B
	move-result-object p0
	return-object p0
.end method

.method private static toByteArrayInternal(Ljava/io/InputStream;Ljava/util/Queue;I)[B
	.locals 7
	.annotation system Ldalvik/annotation/Throws;
	value = {
	Ljava/io/IOException;
	}
	.end annotation
	.annotation system Ldalvik/annotation/Signature;
	value = {
	"(",
	"Ljava/io/InputStream;",
	"Ljava/util/Queue<",
	"[B>;I)[B"
	}
	.end annotation

	invoke-static {p2}, Ljava/lang/Integer;->highestOneBit(I)I
	move-result v0
	const/4 v1, 0x2
	mul-int/lit8 v0, v0, 0x2
	const/16 v2, 0x80
	invoke-static {v2, v0}, Ljava/lang/Math;->max(II)I
	move-result v0
	const/16 v2, 0x2000
	invoke-static {v2, v0}, Ljava/lang/Math;->min(II)I
	move-result v0
	:goto_0
	const/4 v2, -0x1
	const v3, 0x7ffffff7
	if-ge p2, v3, :cond_3
	sub-int/2addr v3, p2
	invoke-static {v0, v3}, Ljava/lang/Math;->min(II)I
	move-result v3
	new-array v4, v3, [B
	invoke-interface {p1, v4}, Ljava/util/Queue;->add(Ljava/lang/Object;)Z
	const/4 v5, 0x0
	:goto_1
	if-ge v5, v3, :cond_1
	sub-int v6, v3, v5
	invoke-virtual {p0, v4, v5, v6}, Ljava/io/InputStream;->read([BII)I
	move-result v6
	if-ne v6, v2, :cond_0
	invoke-static {p1, p2}, Lcom/google/firebase/messaging/ByteStreams;->combineBuffers(Ljava/util/Queue;I)[B
	move-result-object p0
	return-object p0
	:cond_0
	add-int/2addr v5, v6
	add-int/2addr p2, v6
	goto :goto_1
	:cond_1
	int-to-long v2, v0
	const/16 v4, 0x1000
	if-ge v0, v4, :cond_2
	const/4 v0, 0x4
	goto :goto_2
	:cond_2
	const/4 v0, 0x2
	:goto_2
	int-to-long v4, v0
	mul-long v2, v2, v4
	invoke-static {v2, v3}, Lcom/google/firebase/messaging/ByteStreams;->saturatedCast(J)I
	move-result v0
	goto :goto_0
	:cond_3
	invoke-virtual {p0}, Ljava/io/InputStream;->read()I
	move-result p0
	if-ne p0, v2, :cond_4
	invoke-static {p1, v3}, Lcom/google/firebase/messaging/ByteStreams;->combineBuffers(Ljava/util/Queue;I)[B
	move-result-object p0
	return-object p0
	:cond_4
	new-instance p0, Ljava/lang/OutOfMemoryError;
	const-string p1, "input is too large to fit in a byte array"
	invoke-direct {p0, p1}, Ljava/lang/OutOfMemoryError;-><init>(Ljava/lang/String;)V
	throw p0
.end method