|
50 | 50 | import com.google.cloud.storage.UnifiedOpts.ObjectSourceOpt;
|
51 | 51 | import com.google.cloud.storage.UnifiedOpts.ObjectTargetOpt;
|
52 | 52 | import com.google.cloud.storage.UnifiedOpts.Opts;
|
| 53 | +import com.google.common.base.MoreObjects; |
53 | 54 | import com.google.common.collect.ImmutableList;
|
54 | 55 | import com.google.common.collect.ImmutableMap;
|
55 | 56 | import com.google.common.collect.ImmutableSet;
|
|
73 | 74 | import java.util.LinkedList;
|
74 | 75 | import java.util.List;
|
75 | 76 | import java.util.Map;
|
| 77 | +import java.util.Objects; |
76 | 78 | import java.util.Set;
|
77 | 79 | import java.util.concurrent.TimeUnit;
|
78 | 80 | import java.util.stream.Stream;
|
@@ -2778,6 +2780,150 @@ public static Builder newBuilder() {
|
2778 | 2780 | }
|
2779 | 2781 | }
|
2780 | 2782 |
|
| 2783 | + /** |
| 2784 | + * A class to contain all information needed for a Google Cloud Storage Object Move. |
| 2785 | + * |
| 2786 | + * @since 2.48.0 |
| 2787 | + * @see Storage#moveBlob(MoveBlobRequest) |
| 2788 | + */ |
| 2789 | + @TransportCompatibility({Transport.HTTP, Transport.GRPC}) |
| 2790 | + final class MoveBlobRequest { |
| 2791 | + private final BlobId source; |
| 2792 | + private final BlobId target; |
| 2793 | + private final ImmutableList<BlobSourceOption> sourceOptions; |
| 2794 | + private final ImmutableList<BlobTargetOption> targetOptions; |
| 2795 | + |
| 2796 | + MoveBlobRequest( |
| 2797 | + BlobId source, |
| 2798 | + BlobId target, |
| 2799 | + ImmutableList<BlobSourceOption> sourceOptions, |
| 2800 | + ImmutableList<BlobTargetOption> targetOptions) { |
| 2801 | + this.source = source; |
| 2802 | + this.target = target; |
| 2803 | + this.sourceOptions = sourceOptions; |
| 2804 | + this.targetOptions = targetOptions; |
| 2805 | + } |
| 2806 | + |
| 2807 | + public BlobId getSource() { |
| 2808 | + return source; |
| 2809 | + } |
| 2810 | + |
| 2811 | + public BlobId getTarget() { |
| 2812 | + return target; |
| 2813 | + } |
| 2814 | + |
| 2815 | + public List<BlobSourceOption> getSourceOptions() { |
| 2816 | + return sourceOptions; |
| 2817 | + } |
| 2818 | + |
| 2819 | + public List<BlobTargetOption> getTargetOptions() { |
| 2820 | + return targetOptions; |
| 2821 | + } |
| 2822 | + |
| 2823 | + public Builder toBuilder() { |
| 2824 | + return new Builder(source, target, sourceOptions, targetOptions); |
| 2825 | + } |
| 2826 | + |
| 2827 | + public static Builder newBuilder() { |
| 2828 | + return new Builder(); |
| 2829 | + } |
| 2830 | + |
| 2831 | + @Override |
| 2832 | + public boolean equals(Object o) { |
| 2833 | + if (this == o) { |
| 2834 | + return true; |
| 2835 | + } |
| 2836 | + if (!(o instanceof MoveBlobRequest)) { |
| 2837 | + return false; |
| 2838 | + } |
| 2839 | + MoveBlobRequest that = (MoveBlobRequest) o; |
| 2840 | + return Objects.equals(source, that.source) |
| 2841 | + && Objects.equals(target, that.target) |
| 2842 | + && Objects.equals(sourceOptions, that.sourceOptions) |
| 2843 | + && Objects.equals(targetOptions, that.targetOptions); |
| 2844 | + } |
| 2845 | + |
| 2846 | + @Override |
| 2847 | + public int hashCode() { |
| 2848 | + return Objects.hash(source, target, sourceOptions, targetOptions); |
| 2849 | + } |
| 2850 | + |
| 2851 | + @Override |
| 2852 | + public String toString() { |
| 2853 | + return MoreObjects.toStringHelper(this) |
| 2854 | + .add("source", source) |
| 2855 | + .add("target", target) |
| 2856 | + .add("sourceOptions", sourceOptions) |
| 2857 | + .add("targetOptions", targetOptions) |
| 2858 | + .toString(); |
| 2859 | + } |
| 2860 | + |
| 2861 | + public static final class Builder { |
| 2862 | + |
| 2863 | + private BlobId source; |
| 2864 | + private BlobId target; |
| 2865 | + private ImmutableList<BlobSourceOption> sourceOptions; |
| 2866 | + private ImmutableList<BlobTargetOption> targetOptions; |
| 2867 | + |
| 2868 | + private Builder() { |
| 2869 | + this(null, null, ImmutableList.of(), ImmutableList.of()); |
| 2870 | + } |
| 2871 | + |
| 2872 | + private Builder( |
| 2873 | + BlobId source, |
| 2874 | + BlobId target, |
| 2875 | + ImmutableList<BlobSourceOption> sourceOptions, |
| 2876 | + ImmutableList<BlobTargetOption> targetOptions) { |
| 2877 | + this.source = source; |
| 2878 | + this.target = target; |
| 2879 | + this.sourceOptions = sourceOptions; |
| 2880 | + this.targetOptions = targetOptions; |
| 2881 | + } |
| 2882 | + |
| 2883 | + public Builder setSource(BlobId source) { |
| 2884 | + this.source = requireNonNull(source, "source must be non null"); |
| 2885 | + return this; |
| 2886 | + } |
| 2887 | + |
| 2888 | + public Builder setTarget(BlobId target) { |
| 2889 | + this.target = requireNonNull(target, "target must be non null"); |
| 2890 | + return this; |
| 2891 | + } |
| 2892 | + |
| 2893 | + public Builder setSourceOptions(Iterable<BlobSourceOption> sourceOptions) { |
| 2894 | + this.sourceOptions = |
| 2895 | + ImmutableList.copyOf(requireNonNull(sourceOptions, "sourceOptions must be non null")); |
| 2896 | + return this; |
| 2897 | + } |
| 2898 | + |
| 2899 | + public Builder setTargetOptions(Iterable<BlobTargetOption> targetOptions) { |
| 2900 | + this.targetOptions = |
| 2901 | + ImmutableList.copyOf(requireNonNull(targetOptions, "targetOptions must be non null")); |
| 2902 | + return this; |
| 2903 | + } |
| 2904 | + |
| 2905 | + public Builder setSourceOptions(BlobSourceOption... sourceOptions) { |
| 2906 | + this.sourceOptions = |
| 2907 | + ImmutableList.copyOf(requireNonNull(sourceOptions, "sourceOptions must be non null")); |
| 2908 | + return this; |
| 2909 | + } |
| 2910 | + |
| 2911 | + public Builder setTargetOptions(BlobTargetOption... targetOptions) { |
| 2912 | + this.targetOptions = |
| 2913 | + ImmutableList.copyOf(requireNonNull(targetOptions, "targetOptions must be non null")); |
| 2914 | + return this; |
| 2915 | + } |
| 2916 | + |
| 2917 | + public MoveBlobRequest build() { |
| 2918 | + return new MoveBlobRequest( |
| 2919 | + requireNonNull(source, "source must be non null"), |
| 2920 | + requireNonNull(target, "target must be non null"), |
| 2921 | + sourceOptions, |
| 2922 | + targetOptions); |
| 2923 | + } |
| 2924 | + } |
| 2925 | + } |
| 2926 | + |
2781 | 2927 | /**
|
2782 | 2928 | * Creates a new bucket.
|
2783 | 2929 | *
|
@@ -4882,4 +5028,16 @@ default void close() throws Exception {}
|
4882 | 5028 | default BlobWriteSession blobWriteSession(BlobInfo blobInfo, BlobWriteOption... options) {
|
4883 | 5029 | return throwGrpcOnly(fmtMethodName("blobWriteSession", BlobInfo.class, BlobWriteOption.class));
|
4884 | 5030 | }
|
| 5031 | + |
| 5032 | + /** |
| 5033 | + * Atomically move an object from one name to another. |
| 5034 | + * |
| 5035 | + * <p>This new method is an atomic equivalent of the existing {@link Storage#copy(CopyRequest)} + |
| 5036 | + * {@link Storage#delete(BlobId)}, however without the ability to change metadata fields for the |
| 5037 | + * target object. |
| 5038 | + * |
| 5039 | + * @since 2.48.0 |
| 5040 | + */ |
| 5041 | + @TransportCompatibility({Transport.HTTP, Transport.GRPC}) |
| 5042 | + Blob moveBlob(MoveBlobRequest request); |
4885 | 5043 | }
|
0 commit comments