|
@@ -134,7 +134,7 @@ public class Identity extends ConfigSource implements Serializable,
|
134
|
134
|
InvalidIdentityFileException {
|
135
|
135
|
this.file = new ConfigFile(new TextFile(file));
|
136
|
136
|
this.file.setAutomake(true);
|
137
|
|
- initFile(forceDefault, null, file);
|
|
137
|
+ initFile(forceDefault, new FileInputStream(file), new FileInputStream(file));
|
138
|
138
|
myTarget = getTarget(forceDefault);
|
139
|
139
|
}
|
140
|
140
|
|
|
@@ -142,16 +142,18 @@ public class Identity extends ConfigSource implements Serializable,
|
142
|
142
|
* Creates a new read-only identity.
|
143
|
143
|
*
|
144
|
144
|
* @param stream The input stream to read the identity from
|
|
145
|
+ * @param stream2 A second input stream if the first doesn't support marking
|
145
|
146
|
* @param forceDefault Whether to force this identity to be loaded as default
|
146
|
147
|
* identity or not
|
147
|
148
|
* @throws InvalidIdentityFileException Missing required properties
|
148
|
149
|
* @throws IOException Input/output exception
|
149
|
150
|
*/
|
150
|
|
- public Identity(final InputStream stream, final boolean forceDefault) throws IOException,
|
|
151
|
+ public Identity(final InputStream stream, final InputStream stream2,
|
|
152
|
+ final boolean forceDefault) throws IOException,
|
151
|
153
|
InvalidIdentityFileException {
|
152
|
154
|
this.file = new ConfigFile(new TextFile(stream));
|
153
|
155
|
this.file.setAutomake(true);
|
154
|
|
- initFile(forceDefault, stream, null);
|
|
156
|
+ initFile(forceDefault, stream, stream2);
|
155
|
157
|
myTarget = getTarget(forceDefault);
|
156
|
158
|
}
|
157
|
159
|
|
|
@@ -220,34 +222,30 @@ public class Identity extends ConfigSource implements Serializable,
|
220
|
222
|
* @throws InvalidIdentityFileException if the identity file is invalid
|
221
|
223
|
* @throws IOException On I/O exception when reading the identity
|
222
|
224
|
*/
|
223
|
|
- @Precondition("Exactly one of stream and file are specified")
|
224
|
225
|
private void initFile(final boolean forceDefault, final InputStream stream,
|
225
|
|
- final File file) throws InvalidIdentityFileException, IOException {
|
226
|
|
- Logger.assertTrue(file == null ^ stream == null);
|
|
226
|
+ final InputStream newStream) throws InvalidIdentityFileException, IOException {
|
227
|
227
|
|
228
|
|
- if (stream != null && stream.markSupported()) {
|
|
228
|
+ if (stream.markSupported()) {
|
229
|
229
|
stream.mark(Integer.MAX_VALUE);
|
230
|
230
|
}
|
231
|
231
|
|
232
|
232
|
try {
|
233
|
233
|
this.file.read();
|
234
|
|
- } catch (InvalidConfigFileException ex) {
|
235
|
|
- InputStream newStream;
|
|
234
|
+ } catch (InvalidConfigFileException ex) {
|
|
235
|
+ InputStream myStream;
|
236
|
236
|
|
237
|
237
|
if (stream != null && stream.markSupported()) {
|
238
|
238
|
// Not a config file
|
239
|
239
|
stream.reset();
|
240
|
|
- newStream = stream;
|
241
|
|
- } else if (file != null) {
|
242
|
|
- newStream = new FileInputStream(file);
|
|
240
|
+ myStream = stream;
|
243
|
241
|
} else {
|
244
|
|
- throw new IllegalArgumentException("InputStream does not support "
|
245
|
|
- + "mark and contents are not a ConfigFile");
|
|
242
|
+ myStream = newStream;
|
246
|
243
|
}
|
247
|
244
|
|
248
|
245
|
final Properties properties = new Properties();
|
249
|
|
- properties.load(newStream);
|
250
|
|
- newStream.close();
|
|
246
|
+ properties.load(myStream);
|
|
247
|
+
|
|
248
|
+ myStream.close();
|
251
|
249
|
|
252
|
250
|
migrateProperties(properties);
|
253
|
251
|
}
|