@@ -148,11 +148,14 @@ public int getPort() {
148148 * @throws IllegalArgumentException if the port is not between 1 and 65535.
149149 * @throws IllegalStateException if the server cannot be restarted.
150150 */
151- public FakeSftpServerRule setPort (int port ) {
151+ public FakeSftpServerRule setPort (
152+ int port
153+ ) {
152154 if (port < 1 || port > 65535 )
153155 throw new IllegalArgumentException (
154156 "Port cannot be set to " + port
155- + " because only ports between 1 and 65535 are valid." );
157+ + " because only ports between 1 and 65535 are valid."
158+ );
156159 this .port = port ;
157160 if (server != null )
158161 restartServer ();
@@ -166,7 +169,9 @@ private void restartServer() {
166169 server .start ();
167170 } catch (IOException e ) {
168171 throw new IllegalStateException (
169- "The SFTP server cannot be restarted." , e );
172+ "The SFTP server cannot be restarted." ,
173+ e
174+ );
170175 }
171176 }
172177
@@ -178,8 +183,11 @@ private void restartServer() {
178183 * @param encoding the encoding of the file.
179184 * @throws IOException if the file cannot be written.
180185 */
181- public void putFile (String path , String content , Charset encoding )
182- throws IOException {
186+ public void putFile (
187+ String path ,
188+ String content ,
189+ Charset encoding
190+ ) throws IOException {
183191 byte [] contentAsBytes = content .getBytes (encoding );
184192 putFile (path , contentAsBytes );
185193 }
@@ -191,7 +199,10 @@ public void putFile(String path, String content, Charset encoding)
191199 * @param content the files content.
192200 * @throws IOException if the file cannot be written.
193201 */
194- public void putFile (String path , byte [] content ) throws IOException {
202+ public void putFile (
203+ String path ,
204+ byte [] content
205+ ) throws IOException {
195206 verifyThatTestIsRunning ("upload file" );
196207 Path pathAsObject = fileSystem .getPath (path );
197208 ensureDirectoryOfPathExists (pathAsObject );
@@ -206,7 +217,10 @@ public void putFile(String path, byte[] content) throws IOException {
206217 * @throws IOException if the file cannot be written or the input stream
207218 * cannot be read.
208219 */
209- public void putFile (String path , InputStream is ) throws IOException {
220+ public void putFile (
221+ String path ,
222+ InputStream is
223+ ) throws IOException {
210224 verifyThatTestIsRunning ("upload file" );
211225 Path pathAsObject = fileSystem .getPath (path );
212226 ensureDirectoryOfPathExists (pathAsObject );
@@ -218,7 +232,9 @@ public void putFile(String path, InputStream is) throws IOException {
218232 * @param path the directory's path.
219233 * @throws IOException if the directory cannot be created.
220234 */
221- public void createDirectory (String path ) throws IOException {
235+ public void createDirectory (
236+ String path
237+ ) throws IOException {
222238 verifyThatTestIsRunning ("create directory" );
223239 Path pathAsObject = fileSystem .getPath (path );
224240 createDirectories (pathAsObject );
@@ -233,7 +249,10 @@ public void createDirectory(String path) throws IOException {
233249 * @throws IOException if the file cannot be read.
234250 * @throws IllegalStateException if not called from within a test.
235251 */
236- public String getFileContent (String path , Charset encoding ) throws IOException {
252+ public String getFileContent (
253+ String path ,
254+ Charset encoding
255+ ) throws IOException {
237256 byte [] content = getFileContent (path );
238257 return new String (content , encoding );
239258 }
@@ -245,7 +264,9 @@ public String getFileContent(String path, Charset encoding) throws IOException {
245264 * @throws IOException if the file cannot be read.
246265 * @throws IllegalStateException if not called from within a test.
247266 */
248- public byte [] getFileContent (String path ) throws IOException {
267+ public byte [] getFileContent (
268+ String path
269+ ) throws IOException {
249270 verifyThatTestIsRunning ("download file" );
250271 Path pathAsObject = fileSystem .getPath (path );
251272 return readAllBytes (pathAsObject );
@@ -258,19 +279,26 @@ public byte[] getFileContent(String path) throws IOException {
258279 * @return {@code true} iff the file exists and it is not a directory.
259280 * @throws IllegalStateException if not called from within a test.
260281 */
261- public boolean existsFile (String path ) {
282+ public boolean existsFile (
283+ String path
284+ ) {
262285 verifyThatTestIsRunning ("check existence of file" );
263286 Path pathAsObject = fileSystem .getPath (path );
264287 return exists (pathAsObject ) && !isDirectory (pathAsObject );
265288 }
266289
267290 @ Override
268- public Statement apply (Statement base , Description description ) {
291+ public Statement apply (
292+ Statement base ,
293+ Description description
294+ ) {
269295 return new Statement () {
270296 @ Override
271297 public void evaluate () throws Throwable {
272- try (FileSystem fileSystem = createFileSystem ();
273- SshServer server = startServer (fileSystem )) {
298+ try (
299+ FileSystem fileSystem = createFileSystem ();
300+ SshServer server = startServer (fileSystem )
301+ ) {
274302 base .evaluate ();
275303 } finally {
276304 server = null ;
@@ -280,12 +308,15 @@ public void evaluate() throws Throwable {
280308 };
281309 }
282310
283- private FileSystem createFileSystem () throws IOException {
311+ private FileSystem createFileSystem (
312+ ) throws IOException {
284313 fileSystem = newLinux ().build ("FakeSftpServerRule@" + hashCode ());
285314 return fileSystem ;
286315 }
287316
288- private SshServer startServer (FileSystem fileSystem ) throws IOException {
317+ private SshServer startServer (
318+ FileSystem fileSystem
319+ ) throws IOException {
289320 SshServer server = SshServer .setUpDefaultServer ();
290321 server .setPort (port );
291322 server .setKeyPairProvider (new SimpleGeneratorHostKeyProvider ());
@@ -301,22 +332,30 @@ private SshServer startServer(FileSystem fileSystem) throws IOException {
301332 return server ;
302333 }
303334
304- private void ensureDirectoryOfPathExists (Path path ) throws IOException {
335+ private void ensureDirectoryOfPathExists (
336+ Path path
337+ ) throws IOException {
305338 Path directory = path .getParent ();
306339 if (directory != null && !directory .equals (path .getRoot ()))
307340 createDirectories (directory );
308341 }
309342
310- private void verifyThatTestIsRunning (String mode ) {
343+ private void verifyThatTestIsRunning (
344+ String mode
345+ ) {
311346 if (fileSystem == null )
312- throw new IllegalStateException ("Failed to " + mode + " because"
313- + " test has not been started or is already finished." );
347+ throw new IllegalStateException (
348+ "Failed to " + mode + " because test has not been started or"
349+ + " is already finished."
350+ );
314351 }
315352
316353 private static class DoNotClose extends FileSystem {
317354 final FileSystem fileSystem ;
318355
319- DoNotClose (FileSystem fileSystem ) {
356+ DoNotClose (
357+ FileSystem fileSystem
358+ ) {
320359 this .fileSystem = fileSystem ;
321360 }
322361
@@ -326,7 +365,8 @@ public FileSystemProvider provider() {
326365 }
327366
328367 @ Override
329- public void close () throws IOException {
368+ public void close (
369+ ) throws IOException {
330370 //will not be closed
331371 }
332372
@@ -361,12 +401,17 @@ public Set<String> supportedFileAttributeViews() {
361401 }
362402
363403 @ Override
364- public Path getPath (String first , String ... more ) {
404+ public Path getPath (
405+ String first ,
406+ String ... more
407+ ) {
365408 return fileSystem .getPath (first , more );
366409 }
367410
368411 @ Override
369- public PathMatcher getPathMatcher (String syntaxAndPattern ) {
412+ public PathMatcher getPathMatcher (
413+ String syntaxAndPattern
414+ ) {
370415 return fileSystem .getPathMatcher (syntaxAndPattern );
371416 }
372417
0 commit comments