@@ -97,7 +97,7 @@ public SmbSession(SmbShare _smbShare) {
97
97
}
98
98
99
99
/**
100
- * Deletes the file or directory at the specified path.
100
+ * Delete the file or directory at the specified path.
101
101
* @param _path path to a remote file or directory
102
102
* @return true if delete successful, false if resource is non-existent
103
103
* @throws IOException on error conditions returned by a CIFS server
@@ -123,7 +123,7 @@ else if (logger.isInfoEnabled()) {
123
123
}
124
124
125
125
/**
126
- * Returns the contents of the specified SMB resource as an array of SmbFile objects.
126
+ * Return the contents of the specified SMB resource as an array of SmbFile objects.
127
127
* In case the remote resource does not exist, an empty array is returned.
128
128
* @param _path path to a remote directory
129
129
* @return array of SmbFile objects
@@ -162,7 +162,7 @@ else if (logger.isInfoEnabled()) {
162
162
}
163
163
164
164
/**
165
- * Reads the remote resource specified by path and copies its contents to the specified
165
+ * Read the remote resource specified by path and copies its contents to the specified
166
166
* {@link OutputStream}.
167
167
* @param _path path to a remote file
168
168
* @param _outputStream output stream
@@ -190,7 +190,7 @@ public void read(String _path, OutputStream _outputStream) throws IOException {
190
190
}
191
191
192
192
/**
193
- * Writes contents of the specified {@link InputStream} to the remote resource
193
+ * Write contents of the specified {@link InputStream} to the remote resource
194
194
* specified by path. Remote directories are created implicitly as required.
195
195
* @param _inputStream input stream
196
196
* @param _path remote path (of a file) to write to
@@ -237,7 +237,7 @@ public SmbFile write(byte[] _contents, String _path) throws IOException {
237
237
}
238
238
239
239
/**
240
- * Creates the specified remote path if not yet exists.
240
+ * Create the specified remote path if not yet exists.
241
241
* If the specified resource is a file rather than a path, creates all directories leading
242
242
* to that file.
243
243
* @param _path remote path to create
@@ -268,7 +268,7 @@ public boolean mkdir(String _path) throws IOException {
268
268
}
269
269
270
270
/**
271
- * Checks whether the remote resource exists.
271
+ * Check whether the remote resource exists.
272
272
* @param _path remote path
273
273
* @return true if exists, false otherwise
274
274
* @throws IOException on error conditions returned by a CIFS server
@@ -279,7 +279,7 @@ public boolean exists(String _path) throws IOException {
279
279
}
280
280
281
281
/**
282
- * Checks whether the remote resource is a file.
282
+ * Check whether the remote resource is a file.
283
283
* @param _path remote path
284
284
* @return true if resource is a file, false otherwise
285
285
* @throws IOException on error conditions returned by a CIFS server
@@ -290,7 +290,7 @@ public boolean isFile(String _path) throws IOException {
290
290
}
291
291
292
292
/**
293
- * Checks whether the remote resource is a directory.
293
+ * Check whether the remote resource is a directory.
294
294
* @param _path remote path
295
295
* @return true if resource is a directory, false otherwise
296
296
* @throws IOException on error conditions returned by a CIFS server
@@ -387,8 +387,8 @@ public void close() {
387
387
}
388
388
389
389
/**
390
- * Checks with this SMB session is open and ready for work by attempting
391
- * to list remote files and checking for error conditions..
390
+ * Check whether this SMB session is open and ready for work by attempting
391
+ * to list remote files and checking for error conditions.
392
392
* @return true if the session is open, false otherwise
393
393
*/
394
394
@ Override
@@ -455,7 +455,7 @@ private SmbFile createSmbFileObject(String path, Boolean isDirectory) throws IOE
455
455
}
456
456
457
457
/**
458
- * Creates an SMB file object pointing to a remote file.
458
+ * Create an SMB file object pointing to a remote file.
459
459
* @param _path the remote file path
460
460
* @return the {@link SmbFile} for remote path
461
461
* @throws IOException the IO exception
@@ -465,7 +465,7 @@ public SmbFile createSmbFileObject(String _path) throws IOException {
465
465
}
466
466
467
467
/**
468
- * Creates an SMB file object pointing to a remote directory.
468
+ * Create an SMB file object pointing to a remote directory.
469
469
* @param _path the remote directory path
470
470
* @return the {@link SmbFile} for remote path
471
471
* @throws IOException the IO exception
@@ -480,9 +480,43 @@ public String getHostPort() {
480
480
return url .getHost () + ":" + url .getPort ();
481
481
}
482
482
483
+ /**
484
+ * Return the contents of the specified SMB resource as an array of SmbFile filenames.
485
+ * In case the remote resource does not exist, an empty array is returned.
486
+ * @param _path path to a remote directory
487
+ * @return array of SmbFile filenames
488
+ * @throws IOException on error conditions returned by a CIFS server or if the remote resource is not a directory.
489
+ */
483
490
@ Override
484
- public String [] listNames (String path ) {
485
- throw new UnsupportedOperationException ("Not implemented yet" );
491
+ public String [] listNames (String _path ) throws IOException {
492
+ String [] fileNames = new String [0 ];
493
+ try {
494
+ SmbFile smbDir = createSmbDirectoryObject (_path );
495
+ if (!smbDir .exists ()) {
496
+ if (logger .isWarnEnabled ()) {
497
+ logger .warn ("Remote directory [" + _path + "] does not exist. Cannot list resources." );
498
+ }
499
+ return fileNames ;
500
+ }
501
+ else if (!smbDir .isDirectory ()) {
502
+ throw new IOException ("Resource [" + _path + "] is not a directory. Cannot list resources." );
503
+ }
504
+
505
+ fileNames = smbDir .list ();
506
+ }
507
+ catch (SmbException _ex ) {
508
+ throw new IOException ("Failed to list resources in [" + _path + "]." , _ex );
509
+ }
510
+
511
+ if (logger .isDebugEnabled ()) {
512
+ logger .debug ("Successfully listed " + fileNames .length + " resource(s) in [" + _path + "]"
513
+ + ": " + Arrays .toString (fileNames ));
514
+ }
515
+ else if (logger .isInfoEnabled ()) {
516
+ logger .info ("Successfully listed " + fileNames .length + " resource(s) in [" + _path + "]" + "." );
517
+ }
518
+
519
+ return fileNames ;
486
520
}
487
521
488
522
}
0 commit comments