use of org.springframework.core.io.ByteArrayResource in project ignite by apache.
the class IgniteSpringHelperImpl method userVersion.
/**
* {@inheritDoc}
*/
@Override
public String userVersion(ClassLoader ldr, IgniteLogger log) {
assert ldr != null;
assert log != null;
// For system class loader return cached version.
if (ldr == U.gridClassLoader() && SYS_LDR_VER.get() != null)
return SYS_LDR_VER.get();
String usrVer = U.DFLT_USER_VERSION;
InputStream in = ldr.getResourceAsStream(IGNITE_XML_PATH);
if (in != null) {
// Note: use ByteArrayResource instead of InputStreamResource because
// InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(factory);
reader.loadBeanDefinitions(new ByteArrayResource(out.toByteArray()));
usrVer = (String) factory.getBean("userVersion");
usrVer = usrVer == null ? U.DFLT_USER_VERSION : usrVer.trim();
} catch (NoSuchBeanDefinitionException ignored) {
if (log.isInfoEnabled())
log.info("User version is not explicitly defined (will use default version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']');
usrVer = U.DFLT_USER_VERSION;
} catch (BeansException e) {
U.error(log, "Failed to parse Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} catch (IOException e) {
U.error(log, "Failed to read Spring XML file (will use default user version) [file=" + IGNITE_XML_PATH + ", clsLdr=" + ldr + ']', e);
usrVer = U.DFLT_USER_VERSION;
} finally {
U.close(out, log);
}
}
// For system class loader return cached version.
if (ldr == U.gridClassLoader())
SYS_LDR_VER.compareAndSet(null, usrVer);
return usrVer;
}
use of org.springframework.core.io.ByteArrayResource in project ignite by apache.
the class GridUriDeploymentSpringParser method parseTasksDocument.
/**
* Converts given input stream expecting XML inside to
* {@link GridUriDeploymentSpringDocument}.
* <p>
* This is a workaround for the {@link InputStreamResource} which does
* not work properly.
*
* @param in Input stream with XML.
* @param log Logger
* @return Grid wrapper for the input stream.
* @throws org.apache.ignite.spi.IgniteSpiException Thrown if incoming input stream could not be
* read or parsed by {@code Spring} {@link XmlBeanFactory}.
* @see XmlBeanFactory
*/
static GridUriDeploymentSpringDocument parseTasksDocument(InputStream in, IgniteLogger log) throws IgniteSpiException {
assert in != null;
// Note: use ByteArrayResource instead of InputStreamResource because InputStreamResource doesn't work.
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
U.copy(in, out);
XmlBeanFactory factory = new XmlBeanFactory(new ByteArrayResource(out.toByteArray()));
return new GridUriDeploymentSpringDocument(factory);
} catch (BeansException | IOException e) {
throw new IgniteSpiException("Failed to parse spring XML file.", e);
} finally {
U.close(out, log);
}
}
use of org.springframework.core.io.ByteArrayResource in project leopard by tanhaichao.
the class DomainWhiteListConfigImpl method createTable.
protected void createTable() {
StringBuilder sb = new StringBuilder();
sb.append("CREATE TABLE if not exists `leopard_domainwhitelist` (");
sb.append("`domain` varchar(50) NOT NULL DEFAULT '',");
sb.append("`username` varchar(50) NOT NULL DEFAULT '',");
sb.append("`posttime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',");
sb.append("`comment` varchar(255) NOT NULL DEFAULT '',");
sb.append("PRIMARY KEY (`domain`)");
sb.append(");");
String sql = sb.toString();
Resource scripts = new ByteArrayResource(sql.getBytes());
DatabasePopulator populator = new ResourceDatabasePopulator(scripts);
try {
DatabasePopulatorUtils.execute(populator, jdbcTemplate.getDataSource());
} catch (ScriptStatementFailedException e) {
}
}
use of org.springframework.core.io.ByteArrayResource in project leopard by tanhaichao.
the class PropertyPlaceholderLeiImpl method decrypt.
/**
* 解密.
*
* @param resource
* @return
*/
protected Resource decrypt(Resource resource) {
String content;
try {
InputStream input = resource.getInputStream();
content = IOUtils.toString(input);
} catch (IOException e) {
throw new RuntimeException(e.getMessage());
}
Pattern p = Pattern.compile("^[^#=\\s]+$", Pattern.MULTILINE);
Matcher m = p.matcher(content);
StringBuffer sb = new StringBuffer();
while (m.find()) {
String line = m.group();
// System.err.println("body:" + body);
String replacement;
try {
replacement = this.decode(line);
} catch (Exception e) {
System.err.println("app.properties解密出错:" + e.getMessage() + " line:" + line);
replacement = line;
}
m.appendReplacement(sb, replacement);
}
m.appendTail(sb);
// System.out.println("content:" + sb.toString());
return new ByteArrayResource(sb.toString().getBytes());
}
use of org.springframework.core.io.ByteArrayResource in project leopard by tanhaichao.
the class LogConfigLeiImpl method configure.
public static boolean configure(String content) {
// System.err.println("log4j content:" + content);
ByteArrayResource resource2 = new ByteArrayResource(content.getBytes(), "log4j.properties");
try {
InputStream input = resource2.getInputStream();
configure(input);
input.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
LogConfigLeiImpl.content = content;
return true;
}
Aggregations