@@ -32,6 +32,7 @@ public class S3Path
32
32
33
33
public static final String PATH_SEPARATOR = "/" ;
34
34
public static final String PATH_OTHER_INSTANCE_MESSAGE = "other must be an instance of %s" ;
35
+ public static final String PATH_OTHER_INSTANCE_OR_RELATIVE_MESSAGE = "other must be an instance of %s or a relative Path" ;
35
36
36
37
/**
37
38
* S3FileStore which represents the Bucket this path resides in.
@@ -444,16 +445,31 @@ public Path normalize()
444
445
@ Override
445
446
public Path resolve (Path other )
446
447
{
448
+ String otherUri = "" ;
447
449
if (other .isAbsolute ())
448
450
{
449
451
Preconditions .checkArgument (other instanceof S3Path ,
450
- PATH_OTHER_INSTANCE_MESSAGE ,
452
+ PATH_OTHER_INSTANCE_OR_RELATIVE_MESSAGE ,
451
453
S3Path .class .getName ());
452
454
453
455
return other ;
454
456
}
457
+ else if (other instanceof S3Path )
458
+ {
459
+ S3Path otherS3Path = (S3Path ) other ;
460
+ otherUri = otherS3Path .uri ;
461
+ }
462
+ else
463
+ {
464
+ int nameCount = other .getNameCount ();
465
+ for (int i = 0 ; i < nameCount ; i ++)
466
+ {
467
+ if (i > 0 )
468
+ otherUri += PATH_SEPARATOR ;
469
+ otherUri += other .getName (i );
470
+ }
471
+ }
455
472
456
- S3Path otherS3Path = (S3Path ) other ;
457
473
StringBuilder pathBuilder = new StringBuilder ();
458
474
459
475
if (this .isAbsolute ())
@@ -463,9 +479,9 @@ public Path resolve(Path other)
463
479
464
480
pathBuilder .append (this .uri );
465
481
466
- if (!otherS3Path . uri .isEmpty ())
482
+ if (!otherUri .isEmpty ())
467
483
{
468
- pathBuilder .append (PATH_SEPARATOR + otherS3Path . uri );
484
+ pathBuilder .append (PATH_SEPARATOR + otherUri );
469
485
}
470
486
471
487
return new S3Path (this .fileSystem , pathBuilder .toString ());
0 commit comments