@@ -32,6 +32,7 @@ public class S3Path
3232
3333 public static final String PATH_SEPARATOR = "/" ;
3434 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" ;
3536
3637 /**
3738 * S3FileStore which represents the Bucket this path resides in.
@@ -444,16 +445,31 @@ public Path normalize()
444445 @ Override
445446 public Path resolve (Path other )
446447 {
448+ String otherUri = "" ;
447449 if (other .isAbsolute ())
448450 {
449451 Preconditions .checkArgument (other instanceof S3Path ,
450- PATH_OTHER_INSTANCE_MESSAGE ,
452+ PATH_OTHER_INSTANCE_OR_RELATIVE_MESSAGE ,
451453 S3Path .class .getName ());
452454
453455 return other ;
454456 }
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+ }
455472
456- S3Path otherS3Path = (S3Path ) other ;
457473 StringBuilder pathBuilder = new StringBuilder ();
458474
459475 if (this .isAbsolute ())
@@ -463,9 +479,9 @@ public Path resolve(Path other)
463479
464480 pathBuilder .append (this .uri );
465481
466- if (!otherS3Path . uri .isEmpty ())
482+ if (!otherUri .isEmpty ())
467483 {
468- pathBuilder .append (PATH_SEPARATOR + otherS3Path . uri );
484+ pathBuilder .append (PATH_SEPARATOR + otherUri );
469485 }
470486
471487 return new S3Path (this .fileSystem , pathBuilder .toString ());
0 commit comments