Skip to content

Commit b34b01c

Browse files
author
Jerjou Cheng
committed
Fix java style violations.
1 parent d989529 commit b34b01c

File tree

5 files changed

+72
-41
lines changed

5 files changed

+72
-41
lines changed

checkstyle-checker.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@
6969
<!-- required for SuppressWarningsFilter (and other Suppress* rules not used here) -->
7070
<!-- see http://checkstyle.sourceforge.net/config_annotation.html#SuppressWarningsHolder -->
7171
<module name="SuppressWarningsHolder"/>
72+
<!-- required for SuppressWithNearbyCommentFilter -->
73+
<module name="FileContentsHolder"/>
7274

7375
<!-- Checks for Javadoc comments. -->
7476
<!-- See http://checkstyle.sf.net/config_javadoc.html -->
@@ -187,6 +189,10 @@
187189
<!-- Support @SuppressWarnings (added in Checkstyle 5.7) -->
188190
<!-- see http://checkstyle.sourceforge.net/config.html#SuppressWarningsFilter -->
189191
<module name="SuppressWarningsFilter"/>
192+
<!-- Similar to SuppressWarningsFilter, but via comment rather than
193+
annotation. This is needed to suppress warnings on imports, which
194+
SuppressWarnings doesn't support. -->
195+
<module name="SuppressWithNearbyCommentFilter"/>
190196

191197
<!-- Checks properties file for a duplicated properties. -->
192198
<!-- See http://checkstyle.sourceforge.net/config_misc.html#UniqueProperties -->

cloud-storage/xml-api/cmdline-sample/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>doc-samples</artifactId>
66
<groupId>com.google.cloud</groupId>
77
<version>1.0.0</version>
8-
<relativePath>../..</relativePath>
8+
<relativePath>../../..</relativePath>
99
</parent>
1010

1111

cloud-storage/xml-api/cmdline-sample/src/main/java/StorageSample.java

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
/*
33
* Copyright (c) 2014 Google Inc.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6-
* in compliance with the License. You may obtain a copy of the License at
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at
78
*
89
* http://www.apache.org/licenses/LICENSE-2.0
910
*
10-
* Unless required by applicable law or agreed to in writing, software distributed under the License
11-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12-
* or implied. See the License for the specific language governing permissions and limitations under
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14+
* License for the specific language governing permissions and limitations under
1315
* the License.
1416
*/
1517

@@ -20,15 +22,11 @@
2022
import com.google.api.client.http.HttpRequestFactory;
2123
import com.google.api.client.http.HttpResponse;
2224
import com.google.api.client.http.HttpTransport;
23-
import com.google.api.client.json.JsonFactory;
24-
import com.google.api.client.json.jackson2.JacksonFactory;
2525
import com.google.api.client.util.Preconditions;
26-
import com.google.common.io.Files;
2726

2827
import java.io.IOException;
2928
import java.io.StringReader;
3029
import java.io.StringWriter;
31-
import java.nio.charset.Charset;
3230
import java.util.Collections;
3331
import java.net.URLEncoder;
3432

@@ -39,7 +37,14 @@
3937
import javax.xml.transform.stream.StreamResult;
4038
import javax.xml.transform.stream.StreamSource;
4139

42-
public class StorageSample {
40+
/**
41+
* Sample code used in the Cloud Storage Java documentation.
42+
* https://cloud.google.com/storage/docs/xml-api-java-samples
43+
*/
44+
public final class StorageSample {
45+
46+
/** This class is never instantiated. */
47+
private StorageSample() { }
4348

4449
/** Global configuration of Google Cloud Storage OAuth 2.0 scope. */
4550
private static final String STORAGE_SCOPE =
@@ -48,7 +53,12 @@ public class StorageSample {
4853
/** Global instance of the HTTP transport. */
4954
private static HttpTransport httpTransport;
5055

51-
public static void main(String[] args) {
56+
/**
57+
* A command-line handler to display the bucket passed in as an argument.
58+
*
59+
* @param args the array of command-line arguments.
60+
*/
61+
public static void main(final String[] args) {
5262
try {
5363
httpTransport = GoogleNetHttpTransport.newTrustedTransport();
5464
// Check for valid setup.
@@ -62,9 +72,11 @@ public static void main(String[] args) {
6272
.createScoped(Collections.singleton(STORAGE_SCOPE));
6373

6474
// Set up and execute a Google Cloud Storage request.
65-
String URI = "https://storage.googleapis.com/" + URLEncoder.encode(bucketName, "UTF-8");
66-
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(credential);
67-
GenericUrl url = new GenericUrl(URI);
75+
String uri = "https://storage.googleapis.com/"
76+
+ URLEncoder.encode(bucketName, "UTF-8");
77+
HttpRequestFactory requestFactory = httpTransport.createRequestFactory(
78+
credential);
79+
GenericUrl url = new GenericUrl(uri);
6880
HttpRequest request = requestFactory.buildGetRequest(url);
6981
HttpResponse response = request.execute();
7082
String content = response.parseAsString();
@@ -75,12 +87,13 @@ public static void main(String[] args) {
7587
StreamResult xmlOutput = new StreamResult(new StringWriter());
7688

7789
// Configure transformer.
78-
Transformer transformer = TransformerFactory.newInstance().newTransformer(); // An identity
79-
// transformer
90+
Transformer transformer = TransformerFactory.newInstance()
91+
.newTransformer(); // An identity transformer
8092
transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "testing.dtd");
8193
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
8294
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
83-
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
95+
transformer.setOutputProperty(
96+
"{http://xml.apache.org/xslt}indent-amount", "2");
8497
transformer.transform(xmlInput, xmlOutput);
8598

8699
// Pretty print the output XML.

cloud-storage/xml-api/serviceaccount-appengine-sample/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<artifactId>doc-samples</artifactId>
77
<groupId>com.google.cloud</groupId>
88
<version>1.0.0</version>
9-
<relativePath>../..</relativePath>
9+
<relativePath>../../..</relativePath>
1010
</parent>
11-
11+
1212
<groupId>com.google.apis-samples</groupId>
1313
<artifactId>serviceaccounts-appengine-sample</artifactId>
1414
<version>1.0.0</version>

cloud-storage/xml-api/serviceaccount-appengine-sample/src/main/java/com/google/api/client/sample/storage/appengine/serviceaccount/StorageSample.java

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,20 @@
22
/*
33
* Copyright (c) 2012 Google Inc.
44
*
5-
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
6-
* in compliance with the License. You may obtain a copy of the License at
7-
* http://www.apache.org/licenses/LICENSE-2.0.
5+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
6+
* use this file except in compliance with the License. You may obtain a copy of
7+
* the License at http://www.apache.org/licenses/LICENSE-2.0.
88
*
9-
* Unless required by applicable law or agreed to in writing, software distributed under the License
10-
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11-
* or implied. See the License for the specific language governing permissions and limitations under
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
* License for the specific language governing permissions and limitations under
1213
* the License.
1314
*/
1415

1516
package com.google.api.client.sample.storage.appengine.serviceaccount;
1617

17-
import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential;
18+
import com.google.api.client.googleapis.extensions.appengine.auth.oauth2.AppIdentityCredential; // SUPPRESS CHECKSTYLE LineLength
1819
import com.google.api.client.http.GenericUrl;
1920
import com.google.api.client.http.HttpRequest;
2021
import com.google.api.client.http.HttpRequestFactory;
@@ -25,6 +26,8 @@
2526
import java.io.BufferedWriter;
2627
import java.io.IOException;
2728
import java.io.OutputStreamWriter;
29+
import java.net.HttpURLConnection.HTTP_NOT_FOUND;
30+
import java.net.HttpURLConnection.HTTP_OK;
2831
import java.util.Arrays;
2932

3033
import javax.servlet.http.HttpServlet;
@@ -38,9 +41,9 @@
3841
*/
3942
public class StorageSample extends HttpServlet {
4043

41-
private static final long serialVersionUID = 1L;
42-
43-
private static final String GCS_URI = "http://commondatastorage.googleapis.com";
44+
/** The base endpoint for Google Cloud Storage api calls. */
45+
private static final String GCS_URI =
46+
"http://commondatastorage.googleapis.com";
4447

4548
/** Global configuration of Google Cloud Storage OAuth 2.0 scope. */
4649
private static final String STORAGE_SCOPE =
@@ -50,40 +53,49 @@ public class StorageSample extends HttpServlet {
5053
private static final HttpTransport HTTP_TRANSPORT = new NetHttpTransport();
5154

5255
/** Global instance of HTML reference to XSL style sheet. */
53-
String XSL = "\n<?xml-stylesheet href=\"/xsl/listing.xsl\" type=\"text/xsl\"?>\n";
56+
private static final String XSL =
57+
"\n<?xml-stylesheet href=\"/xsl/listing.xsl\" type=\"text/xsl\"?>\n";
5458

5559
@Override
56-
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
60+
protected void doGet(
61+
final HttpServletRequest req, final HttpServletResponse resp)
62+
throws IOException {
5763

5864
try {
59-
AppIdentityCredential credential = new AppIdentityCredential(Arrays.asList(STORAGE_SCOPE));
65+
AppIdentityCredential credential = new AppIdentityCredential(
66+
Arrays.asList(STORAGE_SCOPE));
6067

6168
// Set up and execute Google Cloud Storage request.
6269
String bucketName = req.getRequestURI();
6370
if (bucketName.equals("/")) {
64-
resp.sendError(404, "No bucket specified - append /bucket-name to the URL and retry.");
71+
resp.sendError(
72+
HTTP_NOT_FOUND,
73+
"No bucket specified - append /bucket-name to the URL and retry.");
6574
return;
6675
}
6776
// Remove any trailing slashes, if found.
6877
//[START snippet]
6978
String cleanBucketName = bucketName.replaceAll("/$", "");
70-
String URI = GCS_URI + cleanBucketName;
71-
HttpRequestFactory requestFactory = HTTP_TRANSPORT.createRequestFactory(credential);
72-
GenericUrl url = new GenericUrl(URI);
79+
String uri = GCS_URI + cleanBucketName;
80+
HttpRequestFactory requestFactory =
81+
HTTP_TRANSPORT.createRequestFactory(credential);
82+
GenericUrl url = new GenericUrl(uri);
7383
HttpRequest request = requestFactory.buildGetRequest(url);
7484
HttpResponse response = request.execute();
7585
String content = response.parseAsString();
7686
//[END snippet]
7787

7888
// Display the output XML.
7989
resp.setContentType("text/xml");
80-
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(resp.getOutputStream()));
81-
String formattedContent = content.replaceAll("(<ListBucketResult)", XSL + "$1");
90+
BufferedWriter writer = new BufferedWriter(
91+
new OutputStreamWriter(resp.getOutputStream()));
92+
String formattedContent = content.replaceAll(
93+
"(<ListBucketResult)", XSL + "$1");
8294
writer.append(formattedContent);
8395
writer.flush();
84-
resp.setStatus(200);
96+
resp.setStatus(HTTP_OK);
8597
} catch (Throwable e) {
86-
resp.sendError(404, e.getMessage());
98+
resp.sendError(HTTP_NOT_FOUND, e.getMessage());
8799
}
88100
}
89101
}

0 commit comments

Comments
 (0)