|
22 | 22 | *
|
23 | 23 | * <h3>How It Works</h3>
|
24 | 24 | *
|
25 |
| - * The simplest way to get started is with {@code Paths} and {@code Files}:<pre> {@code |
26 |
| - * |
| 25 | + * The simplest way to get started is with {@code Paths} and {@code Files}: |
| 26 | + * <pre>{@code |
27 | 27 | * Path path = Paths.get(URI.create("gs://bucket/lolcat.csv"));
|
28 |
| - * List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8);}</pre> |
| 28 | + * List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); |
| 29 | + * }</pre> |
| 30 | + * |
| 31 | + * <p>For the complete source code see |
| 32 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/snippets/ReadAllLines.java"> |
| 33 | + * ReadAllLines.java</a>. |
29 | 34 | *
|
30 | 35 | * <p>If you want to configure the bucket per-environment, it might make more sense to use the
|
31 | 36 | * {@code FileSystem} API:
|
32 |
| - * <pre> |
33 |
| - * class Foo { |
34 |
| - * static String bucket = System.getProperty(...); |
35 |
| - * static FileSystem fs = FileSystems.getFileSystem(URI.create("gs://" + bucket)); |
36 |
| - * void bar() { |
37 |
| - * byte[] data = "hello world".getBytes(StandardCharsets.UTF_8); |
38 |
| - * Path path = fs.getPath("/object"); |
39 |
| - * Files.write(path, data); |
40 |
| - * data = Files.readBytes(path); |
41 |
| - * } |
42 |
| - * void doodle() { |
43 |
| - * Path path = fs.getPath("/path/to/doodle.csv"); |
44 |
| - * List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); |
45 |
| - * } |
46 |
| - * }</pre> |
47 |
| - * |
48 |
| - * <p>You can also use InputStream and OutputStream for streaming: |
| 37 | + * <pre>{@code |
| 38 | + * FileSystem fs = FileSystems.getFileSystem(URI.create("gs://bucket")); |
| 39 | + * byte[] data = "hello world".getBytes(StandardCharsets.UTF_8); |
| 40 | + * Path path = fs.getPath("/object"); |
| 41 | + * Files.write(path, data); |
| 42 | + * List<String> lines = Files.readAllLines(path, StandardCharsets.UTF_8); |
| 43 | + * }</pre> |
| 44 | + * |
| 45 | + * <p>For the complete source code see |
| 46 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/snippets/GetFileSystem.java"> |
| 47 | + * GetFileSystem.java</a>. |
| 48 | + * |
| 49 | + * <p>You can also use {@code InputStream} and {@code OutputStream} for streaming: |
49 | 50 | * <pre>
|
50 | 51 | * Path path = Paths.get(URI.create("gs://bucket/lolcat.csv"));
|
51 |
| - * try (InputStream input = Files.openInputStream(path)) { |
52 |
| - * // ... |
53 |
| - * }</pre> |
| 52 | + * try (InputStream input = Files.newInputStream(path)) { |
| 53 | + * // use input stream |
| 54 | + * } |
| 55 | + * </pre> |
| 56 | + * |
| 57 | + * <p>For the complete source code see |
| 58 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/snippets/CreateInputStream.java"> |
| 59 | + * CreateInputStream.java</a>. |
54 | 60 | *
|
55 | 61 | * <p>You can set various attributes using
|
56 | 62 | * {@link com.google.cloud.storage.contrib.nio.CloudStorageOptions CloudStorageOptions} static
|
57 | 63 | * helpers:
|
58 | 64 | * <pre>
|
59 |
| - * Files.write(csvPath, csvLines, StandardCharsets.UTF_8, |
60 |
| - * withMimeType(MediaType.CSV_UTF8), |
61 |
| - * withoutCaching());</pre> |
| 65 | + * Path path = Paths.get(URI.create("gs://bucket/lolcat.csv")); |
| 66 | + * Files.write(path, csvLines, StandardCharsets.UTF_8, |
| 67 | + * withMimeType("text/csv; charset=UTF-8"), |
| 68 | + * withoutCaching()); |
| 69 | + * </pre> |
| 70 | + * |
| 71 | + * <p>For the complete source code see |
| 72 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/snippets/WriteFileWithAttributes.java"> |
| 73 | + * WriteFileWithAttributes.java</a>. |
62 | 74 | *
|
63 | 75 | * <p><b>NOTE:</b> Cloud Storage uses a flat namespace and therefore doesn't support real
|
64 | 76 | * directories. So this library supports what's known as "pseudo-directories". Any path that
|
|
67 | 79 | * would with the normal UNIX file system implementation. You can disable this feature with
|
68 | 80 | * {@link com.google.cloud.storage.contrib.nio.CloudStorageConfiguration#usePseudoDirectories()}.
|
69 | 81 | *
|
70 |
| - * <h3>Unit Testing</h3> |
71 |
| - * |
72 |
| - * <p>Here's a simple unit test:<pre> |
73 |
| - * |
74 |
| - * class MyTest { |
75 |
| - * {@literal @}Rule |
76 |
| - * public final AppEngineRule appEngine = AppEngineRule.builder().build(); |
77 |
| - * |
78 |
| - * {@literal @}Test |
79 |
| - * public test_fileWrite() throws Exception { |
80 |
| - * Path path = Paths.get(URI.create("gs://bucket/traditional")); |
81 |
| - * Files.write(path, "eyebrow".getBytes(StandardCharsets.US_ASCII)); |
82 |
| - * assertEquals("eyebrow", new String(Files.readBytes(path), StandardCharsets.US_ASCII)); |
83 |
| - * } |
84 |
| - * }</pre> |
85 |
| - * |
86 | 82 | * <h3>Non-SPI Interface</h3>
|
87 | 83 | *
|
88 | 84 | * <p>If you don't want to rely on Java SPI, which requires a META-INF file in your jar generated by
|
89 |
| - * Google Auto, you can instantiate this file system directly as follows:<pre> {@code |
| 85 | + * Google Auto, you can instantiate this file system directly as follows: |
90 | 86 | *
|
91 |
| - * CloudStorageFileSystem fs = CloudStorageFileSystemProvider.forBucket("bucket"); |
| 87 | + * <pre> |
| 88 | + * CloudStorageFileSystem fs = CloudStorageFileSystem.forBucket("bucket"); |
92 | 89 | * byte[] data = "hello world".getBytes(StandardCharsets.UTF_8);
|
93 | 90 | * Path path = fs.getPath("/object");
|
94 | 91 | * Files.write(path, data);
|
95 |
| - * data = Files.readBytes(path);}</pre> |
| 92 | + * data = Files.readAllBytes(path); |
| 93 | + * </pre> |
| 94 | + * |
| 95 | + * <p>For the complete source code see |
| 96 | + * <a href="https://github.com/GoogleCloudPlatform/gcloud-java/tree/master/gcloud-java-examples/src/main/java/com/google/cloud/examples/nio/snippets/CreateCloudStorageFileSystem.java"> |
| 97 | + * CreateCloudStorageFileSystem.java</a>. |
96 | 98 | */
|
97 | 99 | @javax.annotation.ParametersAreNonnullByDefault
|
98 | 100 | package com.google.cloud.storage.contrib.nio;
|
0 commit comments