14
14
* limitations under the License.
15
15
*/
16
16
17
- package com .google .gcloud .storage .contrib .nio ;
17
+ package com .google .cloud .storage .contrib .nio ;
18
18
19
19
import static com .google .common .base .Preconditions .checkArgument ;
20
20
import static com .google .common .base .Preconditions .checkNotNull ;
21
21
import static com .google .common .base .Strings .isNullOrEmpty ;
22
- import static com .google .gcloud .storage .contrib .nio .CloudStorageFileSystem .URI_SCHEME ;
23
- import static com .google .gcloud .storage .contrib .nio .CloudStorageUtil .checkBucket ;
24
- import static com .google .gcloud .storage .contrib .nio .CloudStorageUtil .checkNotNullArray ;
25
- import static com .google .gcloud .storage .contrib .nio .CloudStorageUtil .checkPath ;
26
- import static com .google .gcloud .storage .contrib .nio .CloudStorageUtil .stripPathFromUri ;
27
22
28
23
import com .google .auto .service .AutoService ;
29
24
import com .google .common .annotations .VisibleForTesting ;
30
25
import com .google .common .base .MoreObjects ;
31
26
import com .google .common .base .Throwables ;
32
27
import com .google .common .collect .AbstractIterator ;
33
28
import com .google .common .primitives .Ints ;
34
- import com .google .gcloud .storage .Acl ;
35
- import com .google .gcloud .storage .Blob ;
36
- import com .google .gcloud .storage .BlobId ;
37
- import com .google .gcloud .storage .BlobInfo ;
38
- import com .google .gcloud .storage .CopyWriter ;
39
- import com .google .gcloud .storage .Storage ;
40
- import com .google .gcloud .storage .StorageException ;
41
- import com .google .gcloud .storage .StorageOptions ;
29
+ import com .google .cloud .storage .Acl ;
30
+ import com .google .cloud .storage .Blob ;
31
+ import com .google .cloud .storage .BlobId ;
32
+ import com .google .cloud .storage .BlobInfo ;
33
+ import com .google .cloud .storage .CopyWriter ;
34
+ import com .google .cloud .storage .Storage ;
35
+ import com .google .cloud .storage .StorageException ;
36
+ import com .google .cloud .storage .StorageOptions ;
42
37
43
38
import java .io .BufferedInputStream ;
44
39
import java .io .IOException ;
@@ -147,7 +142,7 @@ public CloudStorageFileSystemProvider() {
147
142
148
143
@ Override
149
144
public String getScheme () {
150
- return URI_SCHEME ;
145
+ return CloudStorageFileSystem . URI_SCHEME ;
151
146
}
152
147
153
148
/**
@@ -164,12 +159,12 @@ public CloudStorageFileSystem getFileSystem(URI uri) {
164
159
@ Override
165
160
public CloudStorageFileSystem newFileSystem (URI uri , Map <String , ?> env ) {
166
161
checkArgument (
167
- uri .getScheme ().equalsIgnoreCase (URI_SCHEME ),
162
+ uri .getScheme ().equalsIgnoreCase (CloudStorageFileSystem . URI_SCHEME ),
168
163
"Cloud Storage URIs must have '%s' scheme: %s" ,
169
- URI_SCHEME ,
164
+ CloudStorageFileSystem . URI_SCHEME ,
170
165
uri );
171
166
checkArgument (
172
- !isNullOrEmpty (uri .getHost ()), "%s:// URIs must have a host: %s" , URI_SCHEME , uri );
167
+ !isNullOrEmpty (uri .getHost ()), "%s:// URIs must have a host: %s" , CloudStorageFileSystem . URI_SCHEME , uri );
173
168
checkArgument (
174
169
uri .getPort () == -1
175
170
&& isNullOrEmpty (uri .getPath ())
@@ -178,20 +173,20 @@ && isNullOrEmpty(uri.getFragment())
178
173
&& isNullOrEmpty (uri .getUserInfo ()),
179
174
"GCS FileSystem URIs mustn't have: port, userinfo, path, query, or fragment: %s" ,
180
175
uri );
181
- checkBucket (uri .getHost ());
176
+ CloudStorageUtil . checkBucket (uri .getHost ());
182
177
return new CloudStorageFileSystem (this , uri .getHost (), CloudStorageConfiguration .fromMap (env ));
183
178
}
184
179
185
180
@ Override
186
181
public CloudStoragePath getPath (URI uri ) {
187
- return CloudStoragePath .getPath (getFileSystem (stripPathFromUri (uri )), uri .getPath ());
182
+ return CloudStoragePath .getPath (getFileSystem (CloudStorageUtil . stripPathFromUri (uri )), uri .getPath ());
188
183
}
189
184
190
185
@ Override
191
186
public SeekableByteChannel newByteChannel (
192
187
Path path , Set <? extends OpenOption > options , FileAttribute <?>... attrs ) throws IOException {
193
188
checkNotNull (path );
194
- checkNotNullArray (attrs );
189
+ CloudStorageUtil . checkNotNullArray (attrs );
195
190
if (options .contains (StandardOpenOption .WRITE )) {
196
191
// TODO: Make our OpenOptions implement FileAttribute. Also remove buffer option.
197
192
return newWriteChannel (path , options );
@@ -227,7 +222,7 @@ private SeekableByteChannel newReadChannel(Path path, Set<? extends OpenOption>
227
222
throw new UnsupportedOperationException (option .toString ());
228
223
}
229
224
}
230
- CloudStoragePath cloudPath = checkPath (path );
225
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
231
226
if (cloudPath .seemsLikeADirectoryAndUsePseudoDirectories ()) {
232
227
throw new CloudStoragePseudoDirectoryException (cloudPath );
233
228
}
@@ -237,7 +232,7 @@ private SeekableByteChannel newReadChannel(Path path, Set<? extends OpenOption>
237
232
private SeekableByteChannel newWriteChannel (Path path , Set <? extends OpenOption > options )
238
233
throws IOException {
239
234
240
- CloudStoragePath cloudPath = checkPath (path );
235
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
241
236
if (cloudPath .seemsLikeADirectoryAndUsePseudoDirectories ()) {
242
237
throw new CloudStoragePseudoDirectoryException (cloudPath );
243
238
}
@@ -311,7 +306,7 @@ private SeekableByteChannel newWriteChannel(Path path, Set<? extends OpenOption>
311
306
@ Override
312
307
public InputStream newInputStream (Path path , OpenOption ... options ) throws IOException {
313
308
InputStream result = super .newInputStream (path , options );
314
- CloudStoragePath cloudPath = checkPath (path );
309
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
315
310
int blockSize = cloudPath .getFileSystem ().config ().blockSize ();
316
311
for (OpenOption option : options ) {
317
312
if (option instanceof OptionBlockSize ) {
@@ -323,7 +318,7 @@ public InputStream newInputStream(Path path, OpenOption... options) throws IOExc
323
318
324
319
@ Override
325
320
public boolean deleteIfExists (Path path ) throws IOException {
326
- CloudStoragePath cloudPath = checkPath (path );
321
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
327
322
if (cloudPath .seemsLikeADirectoryAndUsePseudoDirectories ()) {
328
323
throw new CloudStoragePseudoDirectoryException (cloudPath );
329
324
}
@@ -332,7 +327,7 @@ public boolean deleteIfExists(Path path) throws IOException {
332
327
333
328
@ Override
334
329
public void delete (Path path ) throws IOException {
335
- CloudStoragePath cloudPath = checkPath (path );
330
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
336
331
if (!deleteIfExists (cloudPath )) {
337
332
throw new NoSuchFileException (cloudPath .toString ());
338
333
}
@@ -361,7 +356,7 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
361
356
boolean setContentEncoding = false ;
362
357
boolean setContentDisposition = false ;
363
358
364
- CloudStoragePath toPath = checkPath (target );
359
+ CloudStoragePath toPath = CloudStorageUtil . checkPath (target );
365
360
BlobInfo .Builder tgtInfoBuilder = BlobInfo .builder (toPath .getBlobId ()).contentType ("" );
366
361
367
362
int blockSize = -1 ;
@@ -402,7 +397,7 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
402
397
}
403
398
}
404
399
405
- CloudStoragePath fromPath = checkPath (source );
400
+ CloudStoragePath fromPath = CloudStorageUtil . checkPath (source );
406
401
407
402
blockSize =
408
403
blockSize != -1
@@ -470,15 +465,15 @@ public void copy(Path source, Path target, CopyOption... options) throws IOExcep
470
465
471
466
@ Override
472
467
public boolean isSameFile (Path path , Path path2 ) {
473
- return checkPath (path ).equals (checkPath (path2 ));
468
+ return CloudStorageUtil . checkPath (path ).equals (CloudStorageUtil . checkPath (path2 ));
474
469
}
475
470
476
471
/**
477
472
* Always returns {@code false}, because GCS doesn't support hidden files.
478
473
*/
479
474
@ Override
480
475
public boolean isHidden (Path path ) {
481
- checkPath (path );
476
+ CloudStorageUtil . checkPath (path );
482
477
return false ;
483
478
}
484
479
@@ -494,7 +489,7 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
494
489
throw new UnsupportedOperationException (mode .toString ());
495
490
}
496
491
}
497
- CloudStoragePath cloudPath = checkPath (path );
492
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
498
493
if (cloudPath .seemsLikeADirectoryAndUsePseudoDirectories ()) {
499
494
return ;
500
495
}
@@ -508,11 +503,11 @@ public void checkAccess(Path path, AccessMode... modes) throws IOException {
508
503
public <A extends BasicFileAttributes > A readAttributes (
509
504
Path path , Class <A > type , LinkOption ... options ) throws IOException {
510
505
checkNotNull (type );
511
- checkNotNullArray (options );
506
+ CloudStorageUtil . checkNotNullArray (options );
512
507
if (type != CloudStorageFileAttributes .class && type != BasicFileAttributes .class ) {
513
508
throw new UnsupportedOperationException (type .getSimpleName ());
514
509
}
515
- CloudStoragePath cloudPath = checkPath (path );
510
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
516
511
if (cloudPath .seemsLikeADirectoryAndUsePseudoDirectories ()) {
517
512
@ SuppressWarnings ("unchecked" )
518
513
A result = (A ) new CloudStoragePseudoDirectoryAttributes (cloudPath );
@@ -543,11 +538,11 @@ public Map<String, Object> readAttributes(Path path, String attributes, LinkOpti
543
538
public <V extends FileAttributeView > V getFileAttributeView (
544
539
Path path , Class <V > type , LinkOption ... options ) {
545
540
checkNotNull (type );
546
- checkNotNullArray (options );
541
+ CloudStorageUtil . checkNotNullArray (options );
547
542
if (type != CloudStorageFileAttributeView .class && type != BasicFileAttributeView .class ) {
548
543
throw new UnsupportedOperationException (type .getSimpleName ());
549
544
}
550
- CloudStoragePath cloudPath = checkPath (path );
545
+ CloudStoragePath cloudPath = CloudStorageUtil . checkPath (path );
551
546
@ SuppressWarnings ("unchecked" )
552
547
V result = (V ) new CloudStorageFileAttributeView (storage , cloudPath );
553
548
return result ;
@@ -558,13 +553,13 @@ public <V extends FileAttributeView> V getFileAttributeView(
558
553
*/
559
554
@ Override
560
555
public void createDirectory (Path dir , FileAttribute <?>... attrs ) {
561
- checkPath (dir );
562
- checkNotNullArray (attrs );
556
+ CloudStorageUtil . checkPath (dir );
557
+ CloudStorageUtil . checkNotNullArray (attrs );
563
558
}
564
559
565
560
@ Override
566
561
public DirectoryStream <Path > newDirectoryStream (Path dir , final Filter <? super Path > filter ) {
567
- final CloudStoragePath cloudPath = checkPath (dir );
562
+ final CloudStoragePath cloudPath = CloudStorageUtil . checkPath (dir );
568
563
checkNotNull (filter );
569
564
String prefix = cloudPath .toString ();
570
565
final Iterator <Blob > blobIterator = storage .list (cloudPath .bucket (), Storage .BlobListOption .prefix (prefix ), Storage .BlobListOption .fields ()).iterateAll ();
0 commit comments