org.springframework.core.io.AbstractResource Java Examples

The following examples show how to use org.springframework.core.io.AbstractResource. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: YamlMapFactoryBeanTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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());
}
 
Example #2
Source File: YamlMapFactoryBeanTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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());
}
 
Example #3
Source File: YamlMapFactoryBeanTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: CompensablePropertySource.java    From ByteTCC with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;

}
 
Example #5
Source File: TransactionPropertySource.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;

}
 
Example #6
Source File: ConnectorResourcePropertySource.java    From ByteJTA with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example #7
Source File: DifidoClient.java    From difido-reports with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #8
Source File: StaticAssetsRequestHandler.java    From engine with GNU General Public License v3.0 5 votes vote down vote up
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();
        }

    };
}