List of usage examples for org.springframework.core.io Resource toString
public String toString()
From source file:com.hmsinc.epicenter.classifier.ClassifierFactory.java
/** * Creates a classifier using the given resource. * //from w w w.j a v a2 s . c om * @param resource * @return classificationEngine */ public static ClassificationEngine createClassifier(final Resource resource) throws IOException { Validate.notNull(resource, "Resource was null!"); if (!resource.exists()) { throw new IOException("Resource " + resource.toString() + " does not exist."); } ClassificationEngine engine = null; try { engine = instantiateClassifier(resource); } catch (Exception e) { throw new RuntimeException(e); } return engine; }
From source file:com.wavemaker.commons.classloader.ClassLoaderUtils.java
/** * Returns the File object associated with the given classpath-based path. * //from ww w . j a v a 2s . c o m * Note that this method won't work as expected if the file exists in a jar. This method will throw an IOException * in that case. * * @param path The path to search for. * @return The File object associated with the given path. * @throws IOException */ public static Resource getClasspathFile(String path) throws IOException { Resource ret = new ClassPathResource(path); if (!ret.exists()) { // must have come from a jar or some other obscure location // that we didn't expect throw new IOException("Cannot access " + ret.toString()); } return ret; }
From source file:nl.flotsam.hamcrest.schema.relaxng.RelaxNGMatchers.java
/** * Creates a RelaxNG matcher based on a {@link Resource} object pointing to a RelaxNG schema. (XML Syntax) *///from w ww . ja va 2 s .c o m public static TypeSafeDiagnosingMatcher<Object> isValidatedBy(Resource resource) { VerifierFactory factory = new com.sun.msv.verifier.jarv.TheFactoryImpl(); InputStream in = null; try { URI uri = resource.getURI(); in = resource.getInputStream(); if (uri == null) { return isValidatedBy(factory.compileSchema(in), resource.toString()); } else { return isValidatedBy(factory.compileSchema(in, resource.getURI().toASCIIString()), resource.getFilename()); } } catch (Exception e) { throw new IllegalStateException("Failed to construct matcher", e); } finally { IOUtils.closeQuietly(in); } }
From source file:com.glaf.core.entity.mybatis.MyBatisSessionFactory.java
protected static void reloadSessionFactory() { long start = System.currentTimeMillis(); Set<String> mappers = new HashSet<String>(); Configuration configuration = new Configuration(); String path = SystemProperties.getConfigRootPath() + "/conf/mapper"; try {/*w w w.j av a 2s .c o m*/ Map<String, byte[]> dataMap = getLibMappers(); for (int i = 0; i < dataMap.size(); i++) { Set<Entry<String, byte[]>> entrySet = dataMap.entrySet(); for (Entry<String, byte[]> entry : entrySet) { String key = entry.getKey(); if (key.indexOf("/") != -1) { key = key.substring(key.lastIndexOf("/"), key.length()); } byte[] bytes = entry.getValue(); String filename = path + "/" + key; try { FileUtils.save(filename, bytes); } catch (Exception ex) { ex.printStackTrace(); } } } List<String> list = getClassPathMappers(); for (int i = 0; i < list.size(); i++) { Resource mapperLocation = new FileSystemResource(list.get(i)); try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder(mapperLocation.getInputStream(), configuration, mapperLocation.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); mappers.add(mapperLocation.getFilename()); } catch (Exception ex) { ex.printStackTrace(); throw new NestedIOException("Failed to parse mapping resource: '" + mapperLocation + "'", ex); } finally { ErrorContext.instance().reset(); } } File dir = new File(path); if (dir.exists() && dir.isDirectory()) { File contents[] = dir.listFiles(); if (contents != null) { for (int i = 0; i < contents.length; i++) { if (contents[i].isFile() && contents[i].getName().endsWith("Mapper.xml")) { if (mappers.contains(contents[i].getName())) { continue; } Resource mapperLocation = new FileSystemResource(contents[i]); try { XMLMapperBuilder xmlMapperBuilder = new XMLMapperBuilder( mapperLocation.getInputStream(), configuration, mapperLocation.toString(), configuration.getSqlFragments()); xmlMapperBuilder.parse(); } catch (Exception ex) { ex.printStackTrace(); throw new NestedIOException( "Failed to parse mapping resource: '" + mapperLocation + "'", ex); } finally { ErrorContext.instance().reset(); } } } } } sqlSessionFactory = new SqlSessionFactoryBuilder().build(configuration); } catch (Exception ex) { ex.printStackTrace(); } long time = System.currentTimeMillis() - start; System.out.println("SessionFactory" + (time)); }
From source file:io.wcm.devops.conga.tooling.maven.plugin.ValidateVersionInfoMojo.java
private Properties toProperties(Resource resource) { try (InputStream is = resource.getInputStream()) { Properties props = new Properties(); props.load(is);/*from w ww . j av a 2 s.co m*/ return props; } catch (IOException ex) { throw new RuntimeException("Unable to read properties file: " + resource.toString(), ex); } }
From source file:com.diaimm.april.db.jpa.hibernate.multidbsupport.PersistenceUnitReader.java
/** * Parse and build all persistence unit infos defined in the given XML files. * @param persistenceXmlLocations the resource locations (can be patterns) * @return the resulting PersistenceUnitInfo instances *//* w w w . j ava 2s.c o m*/ public SpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) { ErrorHandler handler = new SimpleSaxErrorHandler(logger); List<SpringPersistenceUnitInfo> infos = new LinkedList<SpringPersistenceUnitInfo>(); String resourceLocation = null; try { for (String location : persistenceXmlLocations) { Resource[] resources = this.resourcePatternResolver.getResources(location); for (Resource resource : resources) { resourceLocation = resource.toString(); InputStream stream = resource.getInputStream(); try { Document document = buildDocument(handler, stream); parseDocument(resource, document, infos); } finally { stream.close(); } } } } catch (IOException ex) { throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex); } catch (SAXException ex) { throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex); } catch (ParserConfigurationException ex) { throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation); } return infos.toArray(new SpringPersistenceUnitInfo[infos.size()]); }
From source file:com.gfactor.jpa.core.MyPersistenceUnitReader.java
/** * Parse and build all persistence unit infos defined in the given XML files. * @param persistenceXmlLocations the resource locations (can be patterns) * @return the resulting PersistenceUnitInfo instances *//*from ww w. j a va 2 s . com*/ public MySpringPersistenceUnitInfo[] readPersistenceUnitInfos(String[] persistenceXmlLocations) { ErrorHandler handler = new SimpleSaxErrorHandler(logger); List<MySpringPersistenceUnitInfo> infos = new LinkedList<MySpringPersistenceUnitInfo>(); String resourceLocation = null; try { for (String location : persistenceXmlLocations) { Resource[] resources = this.resourcePatternResolver.getResources(location); for (Resource resource : resources) { resourceLocation = resource.toString(); InputStream stream = resource.getInputStream(); try { Document document = buildDocument(handler, stream); parseDocument(resource, document, infos); } finally { stream.close(); } } } } catch (IOException ex) { throw new IllegalArgumentException("Cannot parse persistence unit from " + resourceLocation, ex); } catch (SAXException ex) { throw new IllegalArgumentException("Invalid XML in persistence unit from " + resourceLocation, ex); } catch (ParserConfigurationException ex) { throw new IllegalArgumentException("Internal error parsing persistence unit from " + resourceLocation); } return infos.toArray(new MySpringPersistenceUnitInfo[infos.size()]); }
From source file:org.brekka.stillingar.spring.snapshot.WatchedResourceMonitor.java
@Override public boolean canMonitor(Resource resource) { try {//from w ww . j a v a2s . c om return resource.getURI().getScheme().startsWith("file"); } catch (IOException e) { throw new ConfigurationException(String .format("Failed to test watcher for ability to monitor resource '%s'", resource.toString()), e); } }
From source file:podd.util.FormHandler.java
public void setPolicyResource(Resource policyResource) { try {//from w ww .jav a2 s.c o m antiSamyPolicy = Policy.getInstance(policyResource.getFile()); } catch (PolicyException e) { LOGGER.error("Error getting Policy instance for " + policyResource.toString() + ". ", e); } catch (IOException e) { LOGGER.error("Error loading Policy file for " + policyResource.toString() + ". ", e); } }
From source file:de.ecw.zabos.license.License.java
/** * License-File einlesen und dekodieren/*from w ww . ja v a 2 s . c o m*/ * * @param _licensePath * @return */ public boolean readLicense(Resource _licensePath) { try { if (!_licensePath.exists()) { throw new Exception("Lizenz-Datei [" + _licensePath.toString() + "] nicht gefunden"); } File f = _licensePath.getFile(); FileInputStream ifs = new FileInputStream(f); byte[] senc = new byte[512]; if (f.length() != 512) { // Filegroesse stimmt nicht return false; } int i; for (i = 0; i < 512; i++) { senc[i] = (byte) ((ifs.read() ^ xor_key[i]) & 0xFF); } // Bits extrahieren byte[] uenc = new byte[64]; int off = 0; for (i = 0; i < 64; i++) { uenc[i] = (byte) (((senc[off + 0] & 0x01)) | (((senc[off + 1]) & 0x02)) | (((senc[off + 2]) & 0x04)) | (((senc[off + 3]) & 0x08)) | (((senc[off + 4]) & 0x10)) | (((senc[off + 5]) & 0x20)) | (((senc[off + 6]) & 0x40)) | (((senc[off + 7]) & 0x80))); off += 8; } // Felder extrahieren long t; long aus; aus = (uenc[OFF_AUSSTELLUNGSDATUM + 0] & 0xFF); t = (uenc[OFF_AUSSTELLUNGSDATUM + 1] & 0xFF); aus |= t << 8; t = (uenc[OFF_AUSSTELLUNGSDATUM + 2] & 0xFF); aus |= t << 16; t = (uenc[OFF_AUSSTELLUNGSDATUM + 3] & 0xFF); aus |= t << 24; t = (uenc[OFF_AUSSTELLUNGSDATUM + 4] & 0xFF); aus |= t << 32; t = (uenc[OFF_AUSSTELLUNGSDATUM + 5] & 0xFF); aus |= t << 40; t = (uenc[OFF_AUSSTELLUNGSDATUM + 6] & 0xFF); aus |= t << 48; t = (uenc[OFF_AUSSTELLUNGSDATUM + 7] & 0xFF); aus |= t << 56; ausstellungsdatum = new UnixTime(aus); long ab; ab = (uenc[OFF_ABLAUFDATUM + 0] & 0xFF); t = (uenc[OFF_ABLAUFDATUM + 1] & 0xFF); ab |= t << 8; t = (uenc[OFF_ABLAUFDATUM + 2] & 0xFF); ab |= t << 16; t = (uenc[OFF_ABLAUFDATUM + 3] & 0xFF); ab |= t << 24; t = (uenc[OFF_ABLAUFDATUM + 4] & 0xFF); ab |= t << 32; t = (uenc[OFF_ABLAUFDATUM + 5] & 0xFF); ab |= t << 40; t = (uenc[OFF_ABLAUFDATUM + 6] & 0xFF); ab |= t << 48; t = (uenc[OFF_ABLAUFDATUM + 7] & 0xFF); ab |= t << 56; ablaufdatum = new UnixTime(ab); kundennummer = (uenc[OFF_KUNDENNUMMER + 0] & 0xFF) | ((uenc[OFF_KUNDENNUMMER + 1] & 0xFF) << 8) | ((uenc[OFF_KUNDENNUMMER + 2] & 0xFF) << 16) | ((uenc[OFF_KUNDENNUMMER + 3] & 0xFF) << 24); majorVersion = uenc[OFF_MAJOR_VERSION]; minorVersion = uenc[OFF_MINOR_VERSION]; schleifen = (short) ((uenc[OFF_SCHLEIFEN + 0] & 0xFF) | ((uenc[OFF_SCHLEIFEN + 1] & 0xFF) << 8)); personen = (short) ((uenc[OFF_PERSONEN + 0] & 0xFF) | ((uenc[OFF_PERSONEN + 1] & 0xFF) << 8)); off = OFF_USER; i = 0; StringBuffer sb = new StringBuffer(); while ((i++ < 18) && (uenc[off] != 0)) { sb.append((char) (uenc[off++] & 0xFF)); } user = sb.toString(); off = OFF_PASSWD; i = 0; sb = new StringBuffer(); while ((i++ < 18) && (uenc[off] != 0)) { sb.append((char) (uenc[off++] & 0xFF)); } passwd = sb.toString(); // Debug System.err.println("===================================="); System.err.println(" ZABOS LIZENZ INFORMATIONEN:"); System.err.println("===================================="); System.err.println("Ausstellungsdatum: " + ausstellungsdatum); System.err.println("Ablaufdatum: " + ablaufdatum); System.err.println("Kundennummer: " + kundennummer); System.err.println("Version: " + majorVersion + "." + minorVersion); System.err.println("Schleifen: " + schleifen); System.err.println("Personen: " + personen); System.err.println("Gateway-User: " + user); System.err.println("Gateway-Passwd: xxx"); return true; } catch (Exception e) { System.err.println("Die Lizenz-Datei " + _licensePath + " konnte nicht geoeffnet werden (cwd=\"" + System.getProperty("user.dir") + "\")"); e.printStackTrace(); } return false; }