5252import java .io .File ;
5353import java .io .IOException ;
5454import java .io .InputStream ;
55+ import java .nio .charset .StandardCharsets ;
5556import java .util .AbstractMap ;
5657import java .util .Arrays ;
5758import java .util .Collections ;
@@ -191,7 +192,7 @@ public Credentials prompt(final Host bookmark, final String title, final String
191192 assertEquals (new String (expected ), readFile (storage , new Path ("/cyberduckbucket/subdir/alice.txt" , EnumSet .of (AbstractPath .Type .file , AbstractPath .Type .decrypted ))));
192193 }
193194 {
194- final Path mkdir = storage .getFeature (Directory .class ).mkdir (new Path ("/cyberduckbucket/subdir/subsubdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .placeholder , AbstractPath .Type .decrypted )), new TransferStatus ());
195+ storage .getFeature (Directory .class ).mkdir (new Path ("/cyberduckbucket/subdir/subsubdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .placeholder , AbstractPath .Type .decrypted )), new TransferStatus ());
195196 final AttributedList <Path > list = storage .getFeature (ListService .class ).list (new Path ("/cyberduckbucket/subdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .placeholder , AbstractPath .Type .decrypted )), new DisabledListProgressListener ());
196197 storage .getFeature (ListService .class ).list (bucket , new DisabledListProgressListener ());
197198 assertEquals (
@@ -201,6 +202,16 @@ public Credentials prompt(final Host bookmark, final String title, final String
201202 new Path ("/cyberduckbucket/subdir/subsubdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .decrypted )))),
202203 new HashSet <>(list .toList ()));
203204 }
205+ {
206+ final byte [] expected = writeRandomFile (storage , new Path ("/cyberduckbucket/subdir/subsubdir/foo.txt" , EnumSet .of (AbstractPath .Type .file , AbstractPath .Type .decrypted )), 5000 );
207+ final AttributedList <Path > list = storage .getFeature (ListService .class ).list (new Path ("/cyberduckbucket/subdir/subsubdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .placeholder , AbstractPath .Type .decrypted )), new DisabledListProgressListener ());
208+ assertEquals (
209+ new HashSet <>(Collections .singletonList (
210+ new Path ("/cyberduckbucket/subdir/subsubdir/foo.txt" , EnumSet .of (AbstractPath .Type .file , AbstractPath .Type .decrypted )))
211+ ),
212+ new HashSet <>(list .toList ()));
213+ assertEquals (new String (expected ), readFile (storage , new Path ("/cyberduckbucket/subdir/subsubdir/foo.txt" , EnumSet .of (AbstractPath .Type .file , AbstractPath .Type .decrypted ))));
214+ }
204215 {
205216 storage .getFeature (Delete .class ).delete (Collections .singletonList (new Path ("/cyberduckbucket/subdir/bar.txt" , EnumSet .of (AbstractPath .Type .file , AbstractPath .Type .decrypted ))), new DisabledPasswordCallback (), new Delete .DisabledCallback ());
206217 final AttributedList <Path > list = storage .getFeature (ListService .class ).list (new Path ("/cyberduckbucket/subdir" , EnumSet .of (AbstractPath .Type .directory , AbstractPath .Type .placeholder , AbstractPath .Type .decrypted )), new DisabledListProgressListener ());
@@ -288,12 +299,10 @@ public Credentials prompt(final Host bookmark, final String username, final Stri
288299 return content ;
289300 }
290301
291- private static String readFile (final Session <?> session , final Path foo ) throws IOException , BackgroundException {
292- final byte [] buf = new byte [300 ];
293- final TransferStatus status = new TransferStatus ();
294- try (final InputStream inputStream = session .getFeature (Read .class ).read (foo , status , new DisabledConnectionCallback ())) {
295- int l = inputStream .read (buf );
296- return new String (Arrays .copyOfRange (buf , 0 , l ));
302+ private static String readFile (final Session <?> session , final Path file ) throws IOException , BackgroundException {
303+ final Read read = session .getFeature (Read .class );
304+ try (final InputStream in = read .read (file , new TransferStatus ().setLength (file .attributes ().getSize ()), new DisabledConnectionCallback ())) {
305+ return IOUtils .toString (in , StandardCharsets .UTF_8 );
297306 }
298307 }
299308}
0 commit comments