001    /*
002     *   Copyright (C) Christian Schulte, 2005-206
003     *   All rights reserved.
004     *
005     *   Redistribution and use in source and binary forms, with or without
006     *   modification, are permitted provided that the following conditions
007     *   are met:
008     *
009     *     o Redistributions of source code must retain the above copyright
010     *       notice, this list of conditions and the following disclaimer.
011     *
012     *     o Redistributions in binary form must reproduce the above copyright
013     *       notice, this list of conditions and the following disclaimer in
014     *       the documentation and/or other materials provided with the
015     *       distribution.
016     *
017     *   THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
018     *   INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
019     *   AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
020     *   THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT,
021     *   INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
022     *   NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
023     *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
024     *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025     *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
026     *   THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027     *
028     *   $JOMC: SourceFileProcessorTest.java 4265 2012-02-16 21:17:26Z schulte2005 $
029     *
030     */
031    package org.jomc.tools.test;
032    
033    import java.io.File;
034    import java.io.FileInputStream;
035    import java.io.FileOutputStream;
036    import java.io.IOException;
037    import java.io.InputStream;
038    import java.io.OutputStream;
039    import org.apache.commons.io.IOUtils;
040    import org.jomc.model.Implementation;
041    import org.jomc.model.Module;
042    import org.jomc.model.Specification;
043    import org.jomc.tools.SourceFileProcessor;
044    import org.jomc.util.SectionEditor;
045    import org.junit.Test;
046    import static org.junit.Assert.assertEquals;
047    import static org.junit.Assert.assertFalse;
048    import static org.junit.Assert.assertNotNull;
049    import static org.junit.Assert.assertTrue;
050    import static org.junit.Assert.fail;
051    
052    /**
053     * Test cases for class {@code org.jomc.tools.SourceFileProcessor} implementations.
054     *
055     * @author <a href="mailto:schulte2005@users.sourceforge.net">Christian Schulte</a>
056     * @version $JOMC: SourceFileProcessorTest.java 4265 2012-02-16 21:17:26Z schulte2005 $
057     */
058    public class SourceFileProcessorTest extends JomcToolTest
059    {
060    
061        /** Constant to prefix relative resource names with. */
062        private static final String ABSOLUTE_RESOURCE_NAME_PREFIX = "/org/jomc/tools/test/";
063    
064        /** Creates a new {@code SourceFileProcessorTest} instance. */
065        public SourceFileProcessorTest()
066        {
067            super();
068        }
069    
070        /** {@inheritDoc} */
071        @Override
072        public SourceFileProcessor getJomcTool()
073        {
074            return (SourceFileProcessor) super.getJomcTool();
075        }
076    
077        /** {@inheritDoc} */
078        @Override
079        protected SourceFileProcessor newJomcTool()
080        {
081            return new SourceFileProcessor();
082        }
083    
084        @Test
085        @SuppressWarnings( "deprecation" )
086        public final void testSourceFileProcessorNullPointerException() throws Exception
087        {
088            try
089            {
090                this.getJomcTool().getSourceFileType( (Specification) null );
091                fail( "Expected NullPointerException not thrown." );
092            }
093            catch ( final NullPointerException e )
094            {
095                assertNullPointerException( e );
096            }
097    
098            try
099            {
100                this.getJomcTool().getSourceFileType( (Implementation) null );
101                fail( "Expected NullPointerException not thrown." );
102            }
103            catch ( final NullPointerException e )
104            {
105                assertNullPointerException( e );
106            }
107    
108            try
109            {
110                this.getJomcTool().getSourceFilesType( (Specification) null );
111                fail( "Expected NullPointerException not thrown." );
112            }
113            catch ( final NullPointerException e )
114            {
115                assertNullPointerException( e );
116            }
117    
118            try
119            {
120                this.getJomcTool().getSourceFilesType( (Implementation) null );
121                fail( "Expected NullPointerException not thrown." );
122            }
123            catch ( final NullPointerException e )
124            {
125                assertNullPointerException( e );
126            }
127    
128            try
129            {
130                this.getJomcTool().getSourceFileEditor( (Specification) null );
131                fail( "Expected NullPointerException not thrown." );
132            }
133            catch ( final NullPointerException e )
134            {
135                assertNullPointerException( e );
136            }
137    
138            try
139            {
140                this.getJomcTool().getSourceFileEditor( (Implementation) null );
141                fail( "Expected NullPointerException not thrown." );
142            }
143            catch ( final NullPointerException e )
144            {
145                assertNullPointerException( e );
146            }
147    
148            try
149            {
150                this.getJomcTool().manageSourceFiles( null );
151                fail( "Expected NullPointerException not thrown." );
152            }
153            catch ( final NullPointerException e )
154            {
155                assertNullPointerException( e );
156            }
157    
158            try
159            {
160                this.getJomcTool().manageSourceFiles( (Implementation) null, new File( "/" ) );
161                fail( "Expected NullPointerException not thrown." );
162            }
163            catch ( final NullPointerException e )
164            {
165                assertNullPointerException( e );
166            }
167    
168            try
169            {
170                this.getJomcTool().manageSourceFiles( new Implementation(), null );
171                fail( "Expected NullPointerException not thrown." );
172            }
173            catch ( final NullPointerException e )
174            {
175                assertNullPointerException( e );
176            }
177    
178            try
179            {
180                this.getJomcTool().manageSourceFiles( (Module) null, new File( "/" ) );
181                fail( "Expected NullPointerException not thrown." );
182            }
183            catch ( final NullPointerException e )
184            {
185                assertNullPointerException( e );
186            }
187    
188    
189            try
190            {
191                this.getJomcTool().manageSourceFiles( new Module(), null );
192                fail( "Expected NullPointerException not thrown." );
193            }
194            catch ( final NullPointerException e )
195            {
196                assertNullPointerException( e );
197            }
198    
199            try
200            {
201                this.getJomcTool().manageSourceFiles( (Specification) null, new File( "/" ) );
202                fail( "Expected NullPointerException not thrown." );
203            }
204            catch ( final NullPointerException e )
205            {
206                assertNullPointerException( e );
207            }
208    
209            try
210            {
211                this.getJomcTool().manageSourceFiles( new Specification(), null );
212                fail( "Expected NullPointerException not thrown." );
213            }
214            catch ( final NullPointerException e )
215            {
216                assertNullPointerException( e );
217            }
218        }
219    
220        @Test
221        public final void testSourceFileProcessorNotNull() throws Exception
222        {
223            assertNotNull( this.getJomcTool().getSourceFilesType(
224                this.getJomcTool().getModules().getImplementation( "Implementation" ) ) );
225    
226            assertNotNull( this.getJomcTool().getSourceFilesType(
227                this.getJomcTool().getModules().getSpecification( "Specification" ) ) );
228    
229            assertNotNull( this.getJomcTool().getSourceFileEditor() );
230        }
231    
232        @Test
233        public final void testManageSources() throws Exception
234        {
235            this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
236            this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
237    
238            final File nonExistingDirectory = this.getNextOutputDirectory();
239    
240            try
241            {
242                this.getJomcTool().manageSourceFiles( nonExistingDirectory );
243                fail( "Expected IOException not thrown." );
244            }
245            catch ( final IOException e )
246            {
247                assertNotNull( e.getMessage() );
248                System.out.println( e );
249            }
250    
251            try
252            {
253                this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
254                                                      nonExistingDirectory );
255    
256                fail( "Expected IOException not thrown." );
257            }
258            catch ( final IOException e )
259            {
260                assertNotNull( e.getMessage() );
261                System.out.println( e );
262            }
263    
264            try
265            {
266                this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
267                                                      nonExistingDirectory );
268    
269                fail( "Expected IOException not thrown." );
270            }
271            catch ( final IOException e )
272            {
273                assertNotNull( e.getMessage() );
274                System.out.println( e );
275            }
276    
277            try
278            {
279                this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
280                                                      nonExistingDirectory );
281    
282                fail( "Expected IOException not thrown." );
283            }
284            catch ( final IOException e )
285            {
286                assertNotNull( e.getMessage() );
287                System.out.println( e );
288            }
289    
290            File sourcesDirectory = this.getNextOutputDirectory();
291            assertTrue( sourcesDirectory.mkdirs() );
292            this.getJomcTool().manageSourceFiles( sourcesDirectory );
293            this.getJomcTool().manageSourceFiles( sourcesDirectory );
294    
295            sourcesDirectory = this.getNextOutputDirectory();
296            assertTrue( sourcesDirectory.mkdirs() );
297            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
298                                                  sourcesDirectory );
299    
300            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ),
301                                                  sourcesDirectory );
302    
303            final File implementationDirectory = this.getNextOutputDirectory();
304            final File implementationSourceFile = new File( implementationDirectory, "Implementation.java" );
305            assertTrue( implementationDirectory.mkdirs() );
306            long implementationSourceFileLength;
307    
308            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
309                                                  implementationDirectory );
310    
311            implementationSourceFileLength = implementationSourceFile.length();
312            assertTrue( implementationSourceFile.exists() );
313    
314            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
315                                                  implementationDirectory );
316    
317            assertTrue( implementationSourceFile.exists() );
318            assertEquals( implementationSourceFileLength, implementationSourceFile.length() );
319    
320            this.getJomcTool().getTemplateParameters().put( "with-javadoc", Boolean.FALSE );
321    
322            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
323                                                  implementationDirectory );
324    
325            assertTrue( implementationSourceFile.exists() );
326            assertTrue( implementationSourceFile.length() < implementationSourceFileLength );
327    
328            this.getJomcTool().getTemplateParameters().clear();
329    
330            this.getJomcTool().manageSourceFiles(
331                this.getJomcTool().getModules().getImplementation( "ImplementationWithSourceFilesModel" ),
332                implementationDirectory );
333    
334            this.getJomcTool().manageSourceFiles(
335                this.getJomcTool().getModules().getImplementation( "ImplementationWithSourceFilesModel" ),
336                implementationDirectory );
337    
338            final File specificationDirectory = this.getNextOutputDirectory();
339            assertTrue( specificationDirectory.mkdirs() );
340            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
341                                                  specificationDirectory );
342    
343            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
344                                                  specificationDirectory );
345    
346            this.getJomcTool().manageSourceFiles(
347                this.getJomcTool().getModules().getSpecification( "SpecificationWithSourceFilesModel" ),
348                specificationDirectory );
349    
350            this.getJomcTool().manageSourceFiles(
351                this.getJomcTool().getModules().getSpecification( "SpecificationWithSourceFilesModel" ),
352                specificationDirectory );
353    
354            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "IllegalImplementationSource.java.txt",
355                               new File( implementationDirectory, "Implementation.java" ) );
356    
357            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "IllegalSpecificationSource.java.txt",
358                               new File( specificationDirectory, "Specification.java" ) );
359    
360            try
361            {
362                this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
363                                                      implementationDirectory );
364    
365                fail( "Expected IOException not thrown." );
366            }
367            catch ( final IOException e )
368            {
369                assertNotNull( e.getMessage() );
370                System.out.println( e.toString() );
371            }
372    
373            try
374            {
375                this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
376                                                      specificationDirectory );
377    
378                fail( "Expected IOException not thrown." );
379            }
380            catch ( final IOException e )
381            {
382                assertNotNull( e.getMessage() );
383                System.out.println( e.toString() );
384            }
385    
386            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "EmptyImplementationSource.java.txt",
387                               new File( implementationDirectory, "Implementation.java" ) );
388    
389            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "EmptySpecificationSource.java.txt",
390                               new File( specificationDirectory, "Specification.java" ) );
391    
392            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
393                                                  implementationDirectory );
394    
395            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
396                                                  specificationDirectory );
397    
398            this.getJomcTool().setTemplateProfile( "DOES_NOT_EXIST" );
399    
400            sourcesDirectory = this.getNextOutputDirectory();
401            assertTrue( sourcesDirectory.mkdirs() );
402            this.getJomcTool().manageSourceFiles( sourcesDirectory );
403    
404            sourcesDirectory = this.getNextOutputDirectory();
405            assertTrue( sourcesDirectory.mkdirs() );
406            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getModule( "Module" ), sourcesDirectory );
407    
408            sourcesDirectory = this.getNextOutputDirectory();
409            assertTrue( sourcesDirectory.mkdirs() );
410            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
411                                                  sourcesDirectory );
412    
413            sourcesDirectory = this.getNextOutputDirectory();
414            assertTrue( sourcesDirectory.mkdirs() );
415            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
416                                                  sourcesDirectory );
417    
418            this.getJomcTool().setInputEncoding( null );
419            this.getJomcTool().setOutputEncoding( null );
420        }
421    
422        @Test
423        public final void testMandatorySections() throws Exception
424        {
425            final SectionEditor editor = new SectionEditor();
426            final File specificationDirectory = this.getNextOutputDirectory();
427            final File implementationDirectory = this.getNextOutputDirectory();
428    
429            assertTrue( specificationDirectory.mkdirs() );
430            assertTrue( implementationDirectory.mkdirs() );
431    
432            this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
433            this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
434    
435            File f = new File( implementationDirectory, "Implementation.java" );
436            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutAnnotationsSection.java.txt", f );
437            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
438                                                  implementationDirectory );
439    
440            String edited = this.toString( f );
441            editor.edit( edited );
442            assertTrue( editor.isSectionPresent( "Annotations" ) );
443    
444            f = new File( implementationDirectory, "Implementation.java" );
445            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDependenciesSection.java.txt", f );
446            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
447                                                  implementationDirectory );
448    
449            edited = this.toString( f );
450            editor.edit( edited );
451            assertTrue( editor.isSectionPresent( "Dependencies" ) );
452    
453            f = new File( implementationDirectory, "Implementation.java" );
454            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutMessagesSection.java.txt", f );
455            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
456                                                  implementationDirectory );
457    
458            edited = this.toString( f );
459            editor.edit( edited );
460            assertTrue( editor.isSectionPresent( "Messages" ) );
461    
462            f = new File( implementationDirectory, "Implementation.java" );
463            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutPropertiesSection.java.txt", f );
464            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
465                                                  implementationDirectory );
466    
467            edited = this.toString( f );
468            editor.edit( edited );
469            assertTrue( editor.isSectionPresent( "Properties" ) );
470    
471            f = new File( implementationDirectory, "ImplementationOfSpecification.java" );
472            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX
473                               + "ImplementationOfSpecificationWithoutConstructorsSection.java.txt", f );
474    
475            this.getJomcTool().manageSourceFiles(
476                this.getJomcTool().getModules().getImplementation( "ImplementationOfSpecification" ),
477                implementationDirectory );
478    
479            edited = this.toString( f );
480            editor.edit( edited );
481            assertTrue( editor.isSectionPresent( "Constructors" ) );
482    
483            f = new File( specificationDirectory, "Specification.java" );
484            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutAnnotationsSection.java.txt", f );
485            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
486                                                  specificationDirectory );
487    
488            edited = this.toString( f );
489            editor.edit( edited );
490            assertTrue( editor.isSectionPresent( "Annotations" ) );
491    
492            this.getJomcTool().setInputEncoding( null );
493            this.getJomcTool().setOutputEncoding( null );
494        }
495    
496        @Test
497        public final void testOptionalSections() throws Exception
498        {
499            final SectionEditor editor = new SectionEditor();
500            final File implementationDirectory = this.getNextOutputDirectory();
501            final File specificationDirectory = this.getNextOutputDirectory();
502    
503            assertTrue( specificationDirectory.mkdirs() );
504            assertTrue( implementationDirectory.mkdirs() );
505    
506            this.getJomcTool().setInputEncoding( this.getResourceEncoding() );
507            this.getJomcTool().setOutputEncoding( this.getResourceEncoding() );
508    
509            File f = new File( implementationDirectory, "Implementation.java" );
510            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutConstructorsSection.java.txt", f );
511            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
512                                                  implementationDirectory );
513    
514            String edited = this.toString( f );
515            editor.edit( edited );
516            assertFalse( editor.isSectionPresent( "Constructors" ) );
517            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDefaultConstructorSection.java.txt", f );
518            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
519                                                  implementationDirectory );
520    
521            edited = this.toString( f );
522            editor.edit( edited );
523            assertTrue( editor.isSectionPresent( "Constructors" ) );
524            assertTrue( editor.isSectionPresent( "Default Constructor" ) );
525            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutDocumentationSection.java.txt", f );
526            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
527                                                  implementationDirectory );
528    
529            edited = this.toString( f );
530            editor.edit( edited );
531            assertFalse( editor.isSectionPresent( "Documentation" ) );
532            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "ImplementationWithoutLicenseSection.java.txt", f );
533            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getImplementation( "Implementation" ),
534                                                  implementationDirectory );
535    
536            edited = this.toString( f );
537            editor.edit( edited );
538            assertFalse( editor.isSectionPresent( "License Header" ) );
539    
540            f = new File( specificationDirectory, "Specification.java" );
541            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutDocumentationSection.java.txt", f );
542            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
543                                                  specificationDirectory );
544    
545            edited = this.toString( f );
546            editor.edit( edited );
547            assertFalse( editor.isSectionPresent( "Documentation" ) );
548            this.copyResource( ABSOLUTE_RESOURCE_NAME_PREFIX + "SpecificationWithoutLicenseSection.java.txt", f );
549            this.getJomcTool().manageSourceFiles( this.getJomcTool().getModules().getSpecification( "Specification" ),
550                                                  specificationDirectory );
551    
552            edited = this.toString( f );
553            editor.edit( edited );
554            assertFalse( editor.isSectionPresent( "License Header" ) );
555    
556            this.getJomcTool().setInputEncoding( null );
557            this.getJomcTool().setOutputEncoding( null );
558        }
559    
560        @Test
561        public final void testCopyConstructor() throws Exception
562        {
563            try
564            {
565                new SourceFileProcessor( null );
566                fail( "Expected NullPointerException not thrown." );
567            }
568            catch ( final NullPointerException e )
569            {
570                assertNotNull( e.getMessage() );
571                System.out.println( e.toString() );
572            }
573    
574            new SourceFileProcessor( this.getJomcTool() );
575        }
576    
577        private void copyResource( final String resourceName, final File file ) throws IOException
578        {
579            assertTrue( resourceName.startsWith( "/" ) );
580    
581            InputStream in = null;
582            boolean suppressExceptionOnClose = true;
583    
584            try
585            {
586                in = this.getClass().getResourceAsStream( resourceName );
587                assertNotNull( "Resource '" + resourceName + "' not found.", in );
588                OutputStream out = null;
589    
590                try
591                {
592                    out = new FileOutputStream( file );
593                    IOUtils.copy( in, out );
594                    suppressExceptionOnClose = false;
595                }
596                finally
597                {
598                    try
599                    {
600                        if ( out != null )
601                        {
602                            out.close();
603                        }
604                    }
605                    catch ( final IOException e )
606                    {
607                        if ( !suppressExceptionOnClose )
608                        {
609                            throw e;
610                        }
611                    }
612                }
613            }
614            finally
615            {
616                try
617                {
618                    if ( in != null )
619                    {
620                        in.close();
621                    }
622                }
623                catch ( final IOException e )
624                {
625                    if ( !suppressExceptionOnClose )
626                    {
627                        throw e;
628                    }
629                }
630            }
631        }
632    
633        private String toString( final File f ) throws IOException
634        {
635            InputStream in = null;
636            boolean suppressExceptionOnClose = true;
637    
638            try
639            {
640                in = new FileInputStream( f );
641                final String str = IOUtils.toString( in, this.getResourceEncoding() );
642                suppressExceptionOnClose = false;
643                return str;
644            }
645            finally
646            {
647                try
648                {
649                    if ( in != null )
650                    {
651                        in.close();
652                    }
653                }
654                catch ( final IOException e )
655                {
656                    if ( !suppressExceptionOnClose )
657                    {
658                        throw e;
659                    }
660                }
661            }
662        }
663    
664    }