List of usage examples for org.springframework.core.io Resource isOpen
default boolean isOpen()
From source file:org.eclipse.gemini.blueprint.test.internal.util.AbstractStorageTest.java
public void testResource() throws Exception { Resource res = storage.getResource(); assertNotNull(res);//from w ww.java 2 s . c o m assertFalse("underlying storage is not reusable", res.isOpen()); }
From source file:org.data.support.beans.factory.xml.XmlQueryDefinitionReader.java
/** * Detects which kind of validation to perform on the XML file identified * by the supplied {@link Resource}. If the file has a <code>DOCTYPE</code> * definition then DTD validation is used otherwise XSD validation is assumed. * <p>Override this method if you would like to customize resolution * of the {@link #VALIDATION_AUTO} mode. *///w ww. j av a 2 s .c o m protected int detectValidationMode(Resource resource) { if (resource.isOpen()) { throw new QueryDefinitionStoreException( "Passed-in Resource [" + resource + "] contains an open stream: " + "cannot determine validation mode automatically. Either pass in a Resource " + "that is able to create fresh streams, or explicitly specify the validationMode " + "on your XmlBeanDefinitionReader instance."); } InputStream inputStream; try { inputStream = resource.getInputStream(); } catch (IOException ex) { throw new QueryDefinitionStoreException( "Unable to determine validation mode for [" + resource + "]: cannot open InputStream. " + "Did you attempt to load directly from a SAX InputSource without specifying the " + "validationMode on your XmlBeanDefinitionReader instance?", ex); } try { return this.validationModeDetector.detectValidationMode(inputStream); } catch (IOException ex) { throw new QueryDefinitionStoreException("Unable to determine validation mode for [" + resource + "]: an error occurred whilst reading from the InputStream.", ex); } }
From source file:org.openlmis.fulfillment.Resource2DbTest.java
@Test public void insertToDbFromCsvShouldCloseInputStream() throws IOException { // given/*from www.j ava 2s . co m*/ Resource resource = mock(Resource.class); InputStream inputStream = spy(IOUtils.toInputStream("some data")); when(resource.getInputStream()).thenReturn(inputStream); when(template.batchUpdate(any(String.class), any(List.class))).thenReturn(new int[] { 1 }); // when resource2Db.insertToDbFromCsv("sometable", resource); // then verify(inputStream, times(1)).close(); assertFalse(resource.isOpen()); }