下面列出了怎么用org.springframework.core.io.AbstractResource的API类实例代码及写法,或者点击链接到github查看源代码。
@Test
public void testFirstFound() {
this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND);
this.factory.setResources(new AbstractResource() {
@Override
public String getDescription() {
return "non-existent";
}
@Override
public InputStream getInputStream() throws IOException {
throw new IOException("planned");
}
}, new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
}
@Test
public void testFirstFound() {
this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND);
this.factory.setResources(new AbstractResource() {
@Override
public String getDescription() {
return "non-existent";
}
@Override
public InputStream getInputStream() throws IOException {
throw new IOException("planned");
}
}, new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
}
@Test
public void testFirstFound() throws Exception {
this.factory.setResolutionMethod(YamlProcessor.ResolutionMethod.FIRST_FOUND);
this.factory.setResources(new AbstractResource() {
@Override
public String getDescription() {
return "non-existent";
}
@Override
public InputStream getInputStream() throws IOException {
throw new IOException("planned");
}
}, new ByteArrayResource("foo:\n spam: bar".getBytes()));
assertEquals(1, this.factory.getObject().size());
}
public CompensablePropertySource(String name, EncodedResource source) {
super(name, source);
EncodedResource encoded = (EncodedResource) this.getSource();
AbstractResource resource = (AbstractResource) encoded.getResource();
String path = resource.getFilename();
if (StringUtils.isBlank(path)) {
return;
}
String[] values = path.split(":");
if (values.length != 2) {
return;
}
String protocol = values[0];
String resName = values[1];
if ("bytetcc".equalsIgnoreCase(protocol) == false) {
return;
} else if ("loadbalancer.config".equalsIgnoreCase(resName) == false) {
return;
}
this.enabled = true;
}
public TransactionPropertySource(String name, EncodedResource source) {
super(name, source);
EncodedResource encoded = (EncodedResource) this.getSource();
AbstractResource resource = (AbstractResource) encoded.getResource();
String path = resource.getFilename();
if (StringUtils.isBlank(path)) {
return;
}
String[] values = path.split(":");
if (values.length != 2) {
return;
}
String protocol = values[0];
String resName = values[1];
if ("bytejta".equalsIgnoreCase(protocol) == false) {
return;
} else if ("loadbalancer.config".equalsIgnoreCase(resName) == false) {
return;
}
this.enabled = true;
}
public ConnectorResourcePropertySource(String name, EncodedResource source, Map<String, String> aliases) {
super(name, source);
this.aliases.putAll(aliases);
EncodedResource encoded = (EncodedResource) this.getSource();
AbstractResource resource = (AbstractResource) encoded.getResource();
String path = resource.getFilename();
if (StringUtils.isBlank(path)) {
return;
}
String[] values = path.split(":");
if (values.length != 2) {
return;
}
String protocol = values[0];
String resName = values[1];
if ("bytejta".equalsIgnoreCase(protocol) == false) {
return;
} else if ("connector.config".equalsIgnoreCase(resName) == false) {
return;
}
this.enabled = true;
}
private void addFile(int executionId, String uid, AbstractResource resource) {
LinkedMultiValueMap<String, Object> map = new LinkedMultiValueMap<>();
map.add("file", resource);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.MULTIPART_FORM_DATA);
HttpEntity<LinkedMultiValueMap<String, Object>> requestEntity = new HttpEntity<LinkedMultiValueMap<String, Object>>(
map, headers);
template.exchange(base.toString() + "executions/" + executionId + "/details/" + uid + "/file/", HttpMethod.POST,
requestEntity, Void.class);
}
protected Resource toResource(Content content, String path) {
return new AbstractResource() {
@Override
public String getFilename() {
return FilenameUtils.getName(path);
}
@Override
public long lastModified() {
// don't provide timestamp to rely on etag comparison instead
return -1;
}
@Override
public long contentLength() {
return content.getLength();
}
@Override
public String getDescription() {
return null;
}
@Override
public InputStream getInputStream() throws IOException {
return content.getInputStream();
}
};
}