Project

General

Profile

« Previous | Next » 

Revision 8304

Added by Matt Jones over 10 years ago

Reviewed code for all uses of FileInputStream, checking to see if the method should be closing the stream, and if so, closing it in the method as well as in the finally clause to ensure we don't leak file descriptors.

View differences:

RegisterDOITest.java
35 35
import junit.framework.Test;
36 36
import junit.framework.TestSuite;
37 37

  
38
import org.apache.commons.io.IOUtils;
38 39
import org.dataone.client.ObjectFormatCache;
39 40
import org.dataone.configuration.Settings;
40 41
import org.dataone.service.types.v1.Identifier;
......
144 145
		String emlFile = "test/tao.14563.1.xml";
145 146
		InputStream content = null;
146 147
		try {
147
			content = new FileInputStream(emlFile);
148
		    content = new FileInputStream(emlFile);
149
		    testMintAndCreateDOI(content);
150
		    content.close(); 
148 151
		} catch (FileNotFoundException e) {
149 152
			e.printStackTrace();
150 153
			fail(e.getMessage());
154
		} finally {
155
		    IOUtils.closeQuietly(content);
151 156
		}
152
		testMintAndCreateDOI(content);
153 157
	}
154 158
	
155 159
	/**
......
267 271
			InputStream content = null;
268 272
			try {
269 273
				content = new FileInputStream(emlFile);
274
	            
275
	            // create the initial version without DOI
276
	            SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), null);
277
	            sysmeta.setFormatId(ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0").getFormatId());
278
	            Identifier pid = MNodeService.getInstance(request).create(session, guid, content, sysmeta);
279
	            assertEquals(guid.getValue(), pid.getValue());
280

  
281
	            // now publish it
282
	            Identifier publishedIdentifier = MNodeService.getInstance(request).publish(session, pid);
283
	            
284
	            // check for the metadata explicitly, using ezid service
285
	            EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
286
	            ezid.login(ezidUsername, ezidPassword);
287
	            HashMap<String, String> metadata = ezid.getMetadata(publishedIdentifier.getValue());
288
	            assertNotNull(metadata);
289
	            assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
290
	            content.close();
270 291
			} catch (FileNotFoundException e) {
271 292
				e.printStackTrace();
272 293
				fail(e.getMessage());
294
			} finally {
295
			    IOUtils.closeQuietly(content);
273 296
			}
274
			
275
			// create the initial version without DOI
276
			SystemMetadata sysmeta = createSystemMetadata(guid, session.getSubject(), null);
277
	        sysmeta.setFormatId(ObjectFormatCache.getInstance().getFormat("eml://ecoinformatics.org/eml-2.1.0").getFormatId());
278
			Identifier pid = MNodeService.getInstance(request).create(session, guid, content, sysmeta);
279
			assertEquals(guid.getValue(), pid.getValue());
280 297

  
281
			// now publish it
282
			Identifier publishedIdentifier = MNodeService.getInstance(request).publish(session, pid);
283 298
			
284
			// check for the metadata explicitly, using ezid service
285
			EZIDService ezid = new EZIDService(ezidServiceBaseUrl);
286
			ezid.login(ezidUsername, ezidPassword);
287
			HashMap<String, String> metadata = ezid.getMetadata(publishedIdentifier.getValue());
288
			assertNotNull(metadata);
289
			assertTrue(metadata.containsKey(DataCiteProfile.TITLE.toString()));
290
			
291 299
		} catch (Exception e) {
292 300
			e.printStackTrace();
293 301
			fail("Unexpected error: " + e.getMessage());

Also available in: Unified diff