@@ -152,30 +152,33 @@ public OrderedPair<String, Long> concatentateObjects(String mountedRoot, String
152152 file .delete ();
153153 file .createNewFile ();
154154
155- final FileOutputStream fos = new FileOutputStream (file );
156- byte [] buffer = new byte [4096 ];
157-
158- // -> get the input stream for the next file part
159- for (int i = 0 ; i < parts .length ; i ++) {
160- DataHandler nextPart = loadObject (mountedRoot , sourceBucket , parts [i ].getPath ());
161- InputStream is = nextPart .getInputStream ();
162-
163- int len = 0 ;
164- while ((len = is .read (buffer )) > 0 ) {
165- fos .write (buffer , 0 , len );
166- md5 .update (buffer , 0 , len );
167- totalLength += len ;
168- }
169- is .close ();
170-
171- // -> after each file write tell the client we are still here to keep connection alive
172- if (null != client ) {
173- client .write (new String (" " ).getBytes ());
174- client .flush ();
155+ try (final FileOutputStream fos = new FileOutputStream (file );) {
156+ byte [] buffer = new byte [4096 ];
157+
158+ // -> get the input stream for the next file part
159+ for (int i = 0 ; i < parts .length ; i ++) {
160+ DataHandler nextPart = loadObject (mountedRoot , sourceBucket , parts [i ].getPath ());
161+ InputStream is = nextPart .getInputStream ();
162+
163+ int len = 0 ;
164+ while ((len = is .read (buffer )) > 0 ) {
165+ fos .write (buffer , 0 , len );
166+ md5 .update (buffer , 0 , len );
167+ totalLength += len ;
168+ }
169+ is .close ();
170+
171+ // -> after each file write tell the client we are still here to keep connection alive
172+ if (null != client ) {
173+ client .write (new String (" " ).getBytes ());
174+ client .flush ();
175+ }
175176 }
177+ return new OrderedPair <String , Long >(StringHelper .toHexString (md5 .digest ()), new Long (totalLength ));
178+ }catch (IOException e ) {
179+ logger .error ("concatentateObjects unexpected exception " + e .getMessage (), e );
180+ throw new OutOfStorageException (e );
176181 }
177- fos .close ();
178- return new OrderedPair <String , Long >(StringHelper .toHexString (md5 .digest ()), new Long (totalLength ));
179182 //Create an ordered pair whose first element is the MD4 digest as a (lowercase) hex String
180183 } catch (IOException e ) {
181184 logger .error ("concatentateObjects unexpected exception " + e .getMessage (), e );
0 commit comments