类org.springframework.core.io.AbstractResource源码实例Demo

下面列出了怎么用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());
}
 
源代码4 项目: ByteTCC   文件: CompensablePropertySource.java
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;

}
 
源代码5 项目: ByteJTA   文件: TransactionPropertySource.java
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;

}
 
源代码6 项目: ByteJTA   文件: ConnectorResourcePropertySource.java
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;
}
 
源代码7 项目: difido-reports   文件: DifidoClient.java
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);
}
 
源代码8 项目: engine   文件: StaticAssetsRequestHandler.java
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();
        }

    };
}
 
 类方法
 同包方法