17
17
18
18
package com .google .cloud .hadoop .gcsio ;
19
19
20
- import com .google .common .base .Preconditions ;
20
+ import static com .google .common .base .Preconditions .checkArgument ;
21
+
21
22
import com .google .common .collect .ImmutableMap ;
22
23
import java .util .Map ;
23
24
24
25
/**
25
26
* Options for creating objects in GCS.
26
27
*/
27
28
public class CreateObjectOptions {
28
- public static final ImmutableMap <String , byte []> EMPTY_METADATA =
29
- ImmutableMap .<String , byte []>of ();
29
+ public static final ImmutableMap <String , byte []> EMPTY_METADATA = ImmutableMap .of ();
30
30
public static final String DEFAULT_CONTENT_TYPE = "application/octet-stream" ;
31
+ public static final String DEFAULT_CONTENT_ENCODING = null ;
31
32
public static final CreateObjectOptions DEFAULT = new CreateObjectOptions (true );
32
33
33
34
private final boolean overwriteExisting ;
34
35
private final String contentType ;
36
+ private final String contentEncoding ;
35
37
private final Map <String , byte []> metadata ;
36
38
private final boolean requireMetadataMatchForEmptyObjects ;
37
39
@@ -43,7 +45,7 @@ public class CreateObjectOptions {
43
45
* @param overwriteExisting True to overwrite any existing objects with the same name.
44
46
*/
45
47
public CreateObjectOptions (boolean overwriteExisting ) {
46
- this (overwriteExisting , DEFAULT_CONTENT_TYPE , EMPTY_METADATA , false );
48
+ this (overwriteExisting , DEFAULT_CONTENT_TYPE , DEFAULT_CONTENT_ENCODING , EMPTY_METADATA , false );
47
49
}
48
50
49
51
/**
@@ -56,7 +58,7 @@ public CreateObjectOptions(boolean overwriteExisting) {
56
58
* @param metadata A dictionary of metadata to apply to created objects.
57
59
*/
58
60
public CreateObjectOptions (boolean overwriteExisting , Map <String , byte []> metadata ) {
59
- this (overwriteExisting , DEFAULT_CONTENT_TYPE , metadata , true );
61
+ this (overwriteExisting , DEFAULT_CONTENT_TYPE , metadata );
60
62
}
61
63
62
64
/**
@@ -70,30 +72,38 @@ public CreateObjectOptions(boolean overwriteExisting, Map<String, byte[]> metada
70
72
*/
71
73
public CreateObjectOptions (
72
74
boolean overwriteExisting , String contentType , Map <String , byte []> metadata ) {
73
- this (overwriteExisting , contentType , metadata , true );
75
+ this (overwriteExisting , contentType , DEFAULT_CONTENT_ENCODING , metadata , true );
74
76
}
75
77
76
78
/**
77
79
* Construct a new CreateObjectOptions with the spec metadata and content-type.
78
80
*
79
81
* @param overwriteExisting True to overwrite any existing objects with the same name
80
82
* @param contentType content-type for the created file
83
+ * @param contentEncoding content-encoding for the created file
81
84
* @param metadata A dictionary of metadata to apply to created objects
82
- * @param requireMetadataMatchForEmptyObjects if true, when creating an empty object and
83
- * certain types of errors occur, any existing object is checked for an exact metadata
84
- * match to the metadata in this CreateObjectOptions before accepting the creation as
85
- * successful. If false, then on error for creating empty objects, as long as an
86
- * appropriate empty object already exists, even if it holds different metadata than
87
- * provided in this CreateObjectOptions instance, it may be considered created
88
- * successfully.
85
+ * @param requireMetadataMatchForEmptyObjects if true, when creating an empty object and certain
86
+ * types of errors occur, any existing object is checked for an exact metadata match to the
87
+ * metadata in this CreateObjectOptions before accepting the creation as successful. If false,
88
+ * then on error for creating empty objects, as long as an appropriate empty object already
89
+ * exists, even if it holds different metadata than provided in this CreateObjectOptions
90
+ * instance, it may be considered created successfully.
89
91
*/
90
92
public CreateObjectOptions (
91
- boolean overwriteExisting , String contentType , Map <String , byte []> metadata ,
93
+ boolean overwriteExisting ,
94
+ String contentType ,
95
+ String contentEncoding ,
96
+ Map <String , byte []> metadata ,
92
97
boolean requireMetadataMatchForEmptyObjects ) {
93
- Preconditions .checkArgument (!metadata .containsKey ("Content-Type" ),
94
- "The Content-Type metadata must be provided explicitly via the 'contentType' parameter" );
98
+ checkArgument (
99
+ !metadata .containsKey ("Content-Type" ),
100
+ "The Content-Type must be provided explicitly via the 'contentType' parameter" );
101
+ checkArgument (
102
+ !metadata .containsKey ("Content-Encoding" ),
103
+ "The Content-Encoding must be provided explicitly via the 'contentEncoding' parameter" );
95
104
this .overwriteExisting = overwriteExisting ;
96
105
this .contentType = contentType ;
106
+ this .contentEncoding = contentEncoding ;
97
107
this .metadata = metadata ;
98
108
this .requireMetadataMatchForEmptyObjects = requireMetadataMatchForEmptyObjects ;
99
109
}
@@ -112,6 +122,11 @@ public String getContentType() {
112
122
return contentType ;
113
123
}
114
124
125
+ /** Content type to set when creating a file. */
126
+ public String getContentEncoding () {
127
+ return contentEncoding ;
128
+ }
129
+
115
130
/**
116
131
* Custom metadata to apply to this object.
117
132
*/
0 commit comments