Skip to content

Commit d78632c

Browse files
committed
fix: lint
1 parent 1541ad0 commit d78632c

File tree

3 files changed

+105
-101
lines changed

3 files changed

+105
-101
lines changed
Lines changed: 93 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.google.firebase.internal;
22

3+
import com.google.api.client.util.StreamingContent;
4+
35
import java.io.ByteArrayOutputStream;
46
import java.io.IOException;
57
import java.nio.ByteBuffer;
@@ -11,105 +13,104 @@
1113
import org.apache.hc.core5.http.nio.AsyncEntityProducer;
1214
import org.apache.hc.core5.http.nio.DataStreamChannel;
1315

14-
import com.google.api.client.util.StreamingContent;
15-
1616
@SuppressWarnings("deprecation")
1717
public class ApacheHttp2AsyncEntityProducer implements AsyncEntityProducer {
18-
private final ByteBuffer bytebuf;
19-
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
20-
private final ContentType contentType;
21-
private final long contentLength;
22-
private final String contentEncoding;
23-
private final CompletableFuture<Void> writeFuture;
24-
private final AtomicReference<Exception> exception;
25-
26-
public ApacheHttp2AsyncEntityProducer(final StreamingContent content, final ContentType contentType, String contentEncoding, long contentLength, CompletableFuture<Void> writeFuture) {
27-
this.writeFuture = writeFuture;
28-
29-
if (content != null) {
30-
try {
31-
content.writeTo(baos);
32-
} catch (IOException e) {
33-
writeFuture.completeExceptionally(e);
34-
}
35-
}
36-
this.bytebuf = ByteBuffer.wrap(baos.toByteArray());
37-
this.contentType = contentType;
38-
this.contentLength = contentLength;
39-
this.contentEncoding = contentEncoding;
40-
this.exception = new AtomicReference<>();
41-
}
42-
43-
public ApacheHttp2AsyncEntityProducer(ApacheHttp2Request request, CompletableFuture<Void> writeFuture) {
44-
this(
45-
request.getStreamingContent(),
46-
ContentType.parse(request.getContentType()),
47-
request.getContentEncoding(),
48-
request.getContentLength(),
49-
writeFuture
50-
);
51-
}
52-
53-
@Override
54-
public boolean isRepeatable() {
55-
return false;
56-
}
57-
58-
@Override
59-
public String getContentType() {
60-
return contentType != null ? contentType.toString() : null;
61-
}
62-
63-
@Override
64-
public long getContentLength() {
65-
return contentLength;
66-
}
67-
68-
@Override
69-
public int available() {
70-
return Integer.MAX_VALUE;
18+
private final ByteBuffer bytebuf;
19+
private ByteArrayOutputStream baos = new ByteArrayOutputStream();
20+
private final ContentType contentType;
21+
private final long contentLength;
22+
private final String contentEncoding;
23+
private final CompletableFuture<Void> writeFuture;
24+
private final AtomicReference<Exception> exception;
25+
26+
public ApacheHttp2AsyncEntityProducer(StreamingContent content, ContentType contentType,
27+
String contentEncoding, long contentLength, CompletableFuture<Void> writeFuture) {
28+
this.writeFuture = writeFuture;
29+
30+
if (content != null) {
31+
try {
32+
content.writeTo(baos);
33+
} catch (IOException e) {
34+
writeFuture.completeExceptionally(e);
35+
}
7136
}
72-
73-
@Override
74-
public String getContentEncoding() {
75-
return contentEncoding;
37+
this.bytebuf = ByteBuffer.wrap(baos.toByteArray());
38+
this.contentType = contentType;
39+
this.contentLength = contentLength;
40+
this.contentEncoding = contentEncoding;
41+
this.exception = new AtomicReference<>();
42+
}
43+
44+
public ApacheHttp2AsyncEntityProducer(ApacheHttp2Request request,
45+
CompletableFuture<Void> writeFuture) {
46+
this(
47+
request.getStreamingContent(),
48+
ContentType.parse(request.getContentType()),
49+
request.getContentEncoding(),
50+
request.getContentLength(),
51+
writeFuture);
52+
}
53+
54+
@Override
55+
public boolean isRepeatable() {
56+
return false;
57+
}
58+
59+
@Override
60+
public String getContentType() {
61+
return contentType != null ? contentType.toString() : null;
62+
}
63+
64+
@Override
65+
public long getContentLength() {
66+
return contentLength;
67+
}
68+
69+
@Override
70+
public int available() {
71+
return Integer.MAX_VALUE;
72+
}
73+
74+
@Override
75+
public String getContentEncoding() {
76+
return contentEncoding;
77+
}
78+
79+
@Override
80+
public boolean isChunked() {
81+
return false;
82+
}
83+
84+
@Override
85+
public Set<String> getTrailerNames() {
86+
return null;
87+
}
88+
89+
@Override
90+
public void produce(DataStreamChannel channel) throws IOException {
91+
if (bytebuf.hasRemaining()) {
92+
channel.write(bytebuf);
7693
}
77-
78-
@Override
79-
public boolean isChunked() {
80-
return false;
94+
if (!bytebuf.hasRemaining()) {
95+
channel.endStream();
96+
writeFuture.complete(null);
8197
}
98+
}
8299

83-
@Override
84-
public Set<String> getTrailerNames() {
85-
return null;
100+
@Override
101+
public void failed(Exception cause) {
102+
if (exception.compareAndSet(null, cause)) {
103+
releaseResources();
104+
writeFuture.completeExceptionally(cause);
86105
}
106+
}
87107

88-
@Override
89-
public void produce(DataStreamChannel channel) throws IOException {
90-
if (bytebuf.hasRemaining()) {
91-
channel.write(bytebuf);
92-
}
93-
if (!bytebuf.hasRemaining()) {
94-
channel.endStream();
95-
writeFuture.complete(null);
96-
}
97-
}
108+
public final Exception getException() {
109+
return exception.get();
110+
}
98111

99-
@Override
100-
public void failed(Exception cause) {
101-
if (exception.compareAndSet(null, cause)) {
102-
releaseResources();
103-
writeFuture.completeExceptionally(cause);
104-
}
105-
}
106-
107-
public final Exception getException() {
108-
return exception.get();
109-
}
110-
111-
@Override
112-
public void releaseResources() {
113-
bytebuf.clear();
114-
}
112+
@Override
113+
public void releaseResources() {
114+
bytebuf.clear();
115+
}
115116
}

src/main/java/com/google/firebase/internal/ApacheHttp2Request.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public LowLevelHttpResponse execute() throws IOException {
6464

6565
// Make Producer
6666
CompletableFuture<Void> writeFuture = new CompletableFuture<>();
67-
ApacheHttp2AsyncEntityProducer entityProducer = new ApacheHttp2AsyncEntityProducer(this, writeFuture);
67+
ApacheHttp2AsyncEntityProducer entityProducer =
68+
new ApacheHttp2AsyncEntityProducer(this, writeFuture);
6869

6970
// Execute
7071
final CompletableFuture<SimpleHttpResponse> responseFuture = new CompletableFuture<>();

src/test/java/com/google/firebase/internal/ApacheHttp2TransportIT.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
import static org.junit.Assert.assertNull;
55
import static org.junit.Assert.fail;
66

7-
import java.io.IOException;
8-
9-
import org.junit.After;
10-
import org.junit.BeforeClass;
11-
import org.junit.Test;
12-
137
import com.google.api.client.http.HttpRequestFactory;
148
import com.google.api.client.http.HttpResponseException;
159
import com.google.api.client.json.JsonFactory;
@@ -24,9 +18,16 @@
2418
import com.google.firebase.TestOnlyImplFirebaseTrampolines;
2519
import com.google.firebase.auth.MockGoogleCredentials;
2620

21+
import java.io.IOException;
22+
23+
import org.junit.After;
24+
import org.junit.BeforeClass;
25+
import org.junit.Test;
26+
2727
public class ApacheHttp2TransportIT {
2828
private static final GoogleCredentials MOCK_CREDENTIALS = new MockGoogleCredentials("test_token");
29-
private static final ImmutableMap<String, Object> payload = ImmutableMap.<String, Object>of("foo", "bar");
29+
private static final ImmutableMap<String, Object> payload =
30+
ImmutableMap.<String, Object>of("foo", "bar");
3031
// Sets a 1 second delay before response
3132
private static final String DELAY_URL = "https://nghttp2.org/httpbin/delay/1";
3233
private static final String POST_URL = "https://nghttp2.org/httpbin/post";
@@ -162,7 +163,8 @@ public void testWriteTimeoutAuthorizedPost() throws FirebaseException {
162163
}
163164
}
164165

165-
private static ErrorHandlingHttpClient<FirebaseException> getHttpClient(boolean authorized, FirebaseApp app) {
166+
private static ErrorHandlingHttpClient<FirebaseException> getHttpClient(boolean authorized,
167+
FirebaseApp app) {
166168
HttpRequestFactory requestFactory;
167169
if (authorized) {
168170
requestFactory = ApiClientUtils.newAuthorizedRequestFactory(app);

0 commit comments

Comments
 (0)