Skip to content

Commit 12507e2

Browse files
committed
chore: move all ReadProjectionConfigs.ReadAs* nested classes to their own files
1 parent 58557a0 commit 12507e2

File tree

7 files changed

+427
-337
lines changed

7 files changed

+427
-337
lines changed

google-cloud-storage/src/main/java/com/google/cloud/storage/ObjectReadSessionSeekableByteChannel.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
import static com.google.common.base.Preconditions.checkState;
2020

21-
import com.google.cloud.storage.ReadProjectionConfigs.ReadAsChannel;
22-
import com.google.cloud.storage.ReadProjectionConfigs.ReadAsSeekableChannel;
2321
import com.google.common.base.Preconditions;
2422
import java.io.IOException;
2523
import java.nio.ByteBuffer;
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage;
18+
19+
import static java.util.Objects.requireNonNull;
20+
21+
import com.google.api.core.BetaApi;
22+
import com.google.cloud.storage.BaseObjectReadSessionStreamRead.StreamingRead;
23+
import com.google.cloud.storage.ReadProjectionConfigs.BaseConfig;
24+
import com.google.common.base.MoreObjects;
25+
import java.nio.channels.ScatteringByteChannel;
26+
import java.util.Objects;
27+
import javax.annotation.concurrent.Immutable;
28+
29+
@BetaApi
30+
@Immutable
31+
public final class ReadAsChannel extends BaseConfig<ScatteringByteChannel, StreamingRead> {
32+
static final ReadAsChannel INSTANCE = new ReadAsChannel(RangeSpec.all(), Hasher.enabled());
33+
34+
private final RangeSpec range;
35+
private final Hasher hasher;
36+
37+
private ReadAsChannel(RangeSpec range, Hasher hasher) {
38+
super();
39+
this.range = range;
40+
this.hasher = hasher;
41+
}
42+
43+
@BetaApi
44+
public RangeSpec getRange() {
45+
return range;
46+
}
47+
48+
@BetaApi
49+
public ReadAsChannel withRangeSpec(RangeSpec range) {
50+
requireNonNull(range, "range must be non null");
51+
if (this.range.equals(range)) {
52+
return this;
53+
}
54+
return new ReadAsChannel(range, hasher);
55+
}
56+
57+
boolean getCrc32cValidationEnabled() {
58+
return Hasher.enabled().equals(hasher);
59+
}
60+
61+
@BetaApi
62+
ReadAsChannel withCrc32cValidationEnabled(boolean enabled) {
63+
if (enabled && Hasher.enabled().equals(hasher)) {
64+
return this;
65+
} else if (!enabled && Hasher.noop().equals(hasher)) {
66+
return this;
67+
}
68+
return new ReadAsChannel(range, enabled ? Hasher.enabled() : Hasher.noop());
69+
}
70+
71+
@Override
72+
BaseConfig<ScatteringByteChannel, ?> cast() {
73+
return this;
74+
}
75+
76+
@Override
77+
StreamingRead newRead(long readId, RetryContext retryContext) {
78+
return ObjectReadSessionStreamRead.streamingRead(readId, range, hasher, retryContext);
79+
}
80+
81+
@Override
82+
public boolean equals(Object o) {
83+
if (this == o) {
84+
return true;
85+
}
86+
if (!(o instanceof ReadAsChannel)) {
87+
return false;
88+
}
89+
ReadAsChannel that = (ReadAsChannel) o;
90+
return Objects.equals(range, that.range) && Objects.equals(hasher, that.hasher);
91+
}
92+
93+
@Override
94+
public int hashCode() {
95+
return Objects.hash(range, hasher);
96+
}
97+
98+
@Override
99+
public String toString() {
100+
return MoreObjects.toStringHelper(this)
101+
.add("range", range)
102+
.add("crc32cValidationEnabled", getCrc32cValidationEnabled())
103+
.toString();
104+
}
105+
}
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage;
18+
19+
import static java.util.Objects.requireNonNull;
20+
21+
import com.google.api.core.ApiFuture;
22+
import com.google.api.core.BetaApi;
23+
import com.google.cloud.storage.BaseObjectReadSessionStreamRead.AccumulatingRead;
24+
import com.google.cloud.storage.ReadProjectionConfigs.BaseConfig;
25+
import com.google.cloud.storage.ZeroCopySupport.DisposableByteString;
26+
import com.google.common.base.MoreObjects;
27+
import java.util.Objects;
28+
import javax.annotation.concurrent.Immutable;
29+
30+
@Immutable
31+
final class ReadAsFutureByteString
32+
extends BaseConfig<ApiFuture<DisposableByteString>, AccumulatingRead<DisposableByteString>> {
33+
static final ReadAsFutureByteString INSTANCE =
34+
new ReadAsFutureByteString(RangeSpec.all(), Hasher.enabled());
35+
36+
private final RangeSpec range;
37+
private final Hasher hasher;
38+
39+
private ReadAsFutureByteString(RangeSpec range, Hasher hasher) {
40+
super();
41+
this.range = range;
42+
this.hasher = hasher;
43+
}
44+
45+
@BetaApi
46+
public RangeSpec getRange() {
47+
return range;
48+
}
49+
50+
@BetaApi
51+
public ReadAsFutureByteString withRangeSpec(RangeSpec range) {
52+
requireNonNull(range, "range must be non null");
53+
if (this.range.equals(range)) {
54+
return this;
55+
}
56+
return new ReadAsFutureByteString(range, hasher);
57+
}
58+
59+
@BetaApi
60+
boolean getCrc32cValidationEnabled() {
61+
return Hasher.enabled().equals(hasher);
62+
}
63+
64+
@BetaApi
65+
ReadAsFutureByteString withCrc32cValidationEnabled(boolean enabled) {
66+
if (enabled && Hasher.enabled().equals(hasher)) {
67+
return this;
68+
} else if (!enabled && Hasher.noop().equals(hasher)) {
69+
return this;
70+
}
71+
return new ReadAsFutureByteString(range, enabled ? Hasher.enabled() : Hasher.noop());
72+
}
73+
74+
@Override
75+
BaseConfig<ApiFuture<DisposableByteString>, ?> cast() {
76+
return this;
77+
}
78+
79+
@Override
80+
AccumulatingRead<DisposableByteString> newRead(long readId, RetryContext retryContext) {
81+
return ObjectReadSessionStreamRead.createZeroCopyByteStringAccumulatingRead(
82+
readId, range, hasher, retryContext);
83+
}
84+
85+
@Override
86+
public boolean equals(Object o) {
87+
if (this == o) {
88+
return true;
89+
}
90+
if (!(o instanceof ReadAsFutureByteString)) {
91+
return false;
92+
}
93+
ReadAsFutureByteString that = (ReadAsFutureByteString) o;
94+
return Objects.equals(range, that.range) && Objects.equals(hasher, that.hasher);
95+
}
96+
97+
@Override
98+
public int hashCode() {
99+
return Objects.hash(range, hasher);
100+
}
101+
102+
@Override
103+
public String toString() {
104+
return MoreObjects.toStringHelper(this)
105+
.add("range", range)
106+
.add("crc32cValidationEnabled", getCrc32cValidationEnabled())
107+
.toString();
108+
}
109+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.storage;
18+
19+
import static java.util.Objects.requireNonNull;
20+
21+
import com.google.api.core.ApiFuture;
22+
import com.google.api.core.BetaApi;
23+
import com.google.cloud.storage.BaseObjectReadSessionStreamRead.AccumulatingRead;
24+
import com.google.cloud.storage.ReadProjectionConfigs.BaseConfig;
25+
import com.google.common.base.MoreObjects;
26+
import java.util.Objects;
27+
import javax.annotation.concurrent.Immutable;
28+
29+
@BetaApi
30+
@Immutable
31+
final class ReadAsFutureBytes extends BaseConfig<ApiFuture<byte[]>, AccumulatingRead<byte[]>> {
32+
static final ReadAsFutureBytes INSTANCE =
33+
new ReadAsFutureBytes(RangeSpec.all(), Hasher.enabled());
34+
35+
private final RangeSpec range;
36+
private final Hasher hasher;
37+
38+
private ReadAsFutureBytes(RangeSpec range, Hasher hasher) {
39+
super();
40+
this.range = range;
41+
this.hasher = hasher;
42+
}
43+
44+
@BetaApi
45+
public RangeSpec getRange() {
46+
return range;
47+
}
48+
49+
@BetaApi
50+
public ReadAsFutureBytes withRangeSpec(RangeSpec range) {
51+
requireNonNull(range, "range must be non null");
52+
if (this.range.equals(range)) {
53+
return this;
54+
}
55+
return new ReadAsFutureBytes(range, hasher);
56+
}
57+
58+
@BetaApi
59+
boolean getCrc32cValidationEnabled() {
60+
return Hasher.enabled().equals(hasher);
61+
}
62+
63+
@BetaApi
64+
ReadAsFutureBytes withCrc32cValidationEnabled(boolean enabled) {
65+
if (enabled && Hasher.enabled().equals(hasher)) {
66+
return this;
67+
} else if (!enabled && Hasher.noop().equals(hasher)) {
68+
return this;
69+
}
70+
return new ReadAsFutureBytes(range, enabled ? Hasher.enabled() : Hasher.noop());
71+
}
72+
73+
@Override
74+
BaseConfig<ApiFuture<byte[]>, ?> cast() {
75+
return this;
76+
}
77+
78+
@Override
79+
AccumulatingRead<byte[]> newRead(long readId, RetryContext retryContext) {
80+
return ObjectReadSessionStreamRead.createByteArrayAccumulatingRead(
81+
readId, range, hasher, retryContext);
82+
}
83+
84+
@Override
85+
public boolean equals(Object o) {
86+
if (this == o) {
87+
return true;
88+
}
89+
if (!(o instanceof ReadAsFutureBytes)) {
90+
return false;
91+
}
92+
ReadAsFutureBytes that = (ReadAsFutureBytes) o;
93+
return Objects.equals(range, that.range) && Objects.equals(hasher, that.hasher);
94+
}
95+
96+
@Override
97+
public int hashCode() {
98+
return Objects.hash(range, hasher);
99+
}
100+
101+
@Override
102+
public String toString() {
103+
return MoreObjects.toStringHelper(this)
104+
.add("range", range)
105+
.add("crc32cValidationEnabled", getCrc32cValidationEnabled())
106+
.toString();
107+
}
108+
}

0 commit comments

Comments
 (0)