This repository has been archived by the owner on Jan 21, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
/
FileSinkProperties.java
164 lines (130 loc) · 3.98 KB
/
FileSinkProperties.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
* Copyright 2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.cloud.stream.app.file.sink;
import java.io.File;
import javax.validation.constraints.AssertTrue;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.expression.Expression;
import org.springframework.integration.file.support.FileExistsMode;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
/**
* Properties for the file sink.
*
* @author Mark Fisher
* @author Gary Russell
*/
@ConfigurationProperties("file")
@Validated
public class FileSinkProperties {
private static final String DEFAULT_DIR = System.getProperty("java.io.tmpdir") +
File.separator + "file-sink" + File.separator + "output";
private static final String DEFAULT_NAME = "file-sink";
/**
* A flag to indicate whether adding a newline after the write should be suppressed.
*/
private boolean binary = false;
/**
* The charset to use when writing text content.
*/
private String charset = "UTF-8";
/**
* The parent directory of the target file.
*/
private String directory = DEFAULT_DIR;
/**
* The expression to evaluate for the parent directory of the target file.
*/
private Expression directoryExpression;
/**
* The FileExistsMode to use if the target file already exists.
*/
private FileExistsMode mode = FileExistsMode.APPEND;
/**
* The name of the target file.
*/
private String name = DEFAULT_NAME;
/**
* The expression to evaluate for the name of the target file.
*/
private String nameExpression;
/**
* The suffix to append to file name.
*/
private String suffix = "";
public boolean isBinary() {
return binary;
}
public void setBinary(boolean binary) {
this.binary = binary;
}
public String getCharset() {
return charset;
}
public void setCharset(String charset) {
this.charset = charset;
}
public String getDirectory() {
return directory;
}
public void setDirectory(String directory) {
this.directory = directory;
}
public Expression getDirectoryExpression() {
return directoryExpression;
}
public void setDirectoryExpression(Expression directoryExpression) {
this.directoryExpression = directoryExpression;
}
public FileExistsMode getMode() {
return mode;
}
public void setMode(FileExistsMode mode) {
this.mode = mode;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getNameExpression() {
return (nameExpression != null)
? nameExpression + " + '" + getSuffix() + "'"
: "'" + name + getSuffix() + "'";
}
public void setNameExpression(String nameExpression) {
this.nameExpression = nameExpression;
}
public String getSuffix() {
String suffixWithDotIfNecessary = "";
if (StringUtils.hasText(suffix)) {
suffixWithDotIfNecessary = suffix.startsWith(".") ? suffix : "." + suffix;
}
return suffixWithDotIfNecessary;
}
public void setSuffix(String suffix) {
this.suffix = suffix;
}
@AssertTrue(message = "Exactly one of 'name' or 'nameExpression' must be set")
public boolean isMutuallyExclusiveNameAndNameExpression() {
return DEFAULT_NAME.equals(name) || nameExpression == null;
}
@AssertTrue(message = "Exactly one of 'directory' or 'directoryExpression' must be set")
public boolean isMutuallyExclusiveDirectoryAndDirectoryExpression() {
return DEFAULT_DIR.equals(directory) || directoryExpression == null;
}
}