Java Code Examples for org.springframework.util.StreamUtils#emptyInput()

The following examples show how to use org.springframework.util.StreamUtils#emptyInput() . 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: MockHttpServletRequestBuilder.java    From java-technology-stack with MIT License 6 votes vote down vote up
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
	HttpInputMessage message = new HttpInputMessage() {
		@Override
		public InputStream getBody() {
			return (content != null ? new ByteArrayInputStream(content) : StreamUtils.emptyInput());
		}
		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(mediaType);
			return headers;
		}
	};

	try {
		return new FormHttpMessageConverter().read(null, message);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Failed to parse form data in request body", ex);
	}
}
 
Example 2
Source File: MockHttpServletRequestBuilder.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private MultiValueMap<String, String> parseFormData(final MediaType mediaType) {
	HttpInputMessage message = new HttpInputMessage() {
		@Override
		public InputStream getBody() {
			return (content != null ? new ByteArrayInputStream(content) : StreamUtils.emptyInput());
		}
		@Override
		public HttpHeaders getHeaders() {
			HttpHeaders headers = new HttpHeaders();
			headers.setContentType(mediaType);
			return headers;
		}
	};

	try {
		return new FormHttpMessageConverter().read(null, message);
	}
	catch (IOException ex) {
		throw new IllegalStateException("Failed to parse form data in request body", ex);
	}
}
 
Example 3
Source File: PassThroughClob.java    From java-technology-stack with MIT License 6 votes vote down vote up
@Override
public InputStream getAsciiStream() throws SQLException {
	try {
		if (this.content != null) {
			return new ByteArrayInputStream(this.content.getBytes(StandardCharsets.US_ASCII));
		}
		else if (this.characterStream != null) {
			String tempContent = FileCopyUtils.copyToString(this.characterStream);
			return new ByteArrayInputStream(tempContent.getBytes(StandardCharsets.US_ASCII));
		}
		else {
			return (this.asciiStream != null ? this.asciiStream : StreamUtils.emptyInput());
		}
	}
	catch (IOException ex) {
		throw new SQLException("Failed to read stream content: " + ex);
	}
}
 
Example 4
Source File: PassThroughBlob.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Override
public InputStream getBinaryStream() throws SQLException {
	if (this.content != null) {
		return new ByteArrayInputStream(this.content);
	}
	else {
		return (this.binaryStream != null ? this.binaryStream : StreamUtils.emptyInput());
	}
}
 
Example 5
Source File: WxMultipartFile.java    From FastBootWeixin with Apache License 2.0 5 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
    if (!isAvailable()) {
        throw new IllegalStateException("File has been moved - cannot be read again");
    }
    InputStream inputStream = this.fileItem.getInputStream();
    return (inputStream != null ? inputStream : StreamUtils.emptyInput());
}
 
Example 6
Source File: PassThroughClob.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public Reader getCharacterStream() throws SQLException {
	if (this.content != null) {
		return new StringReader(this.content);
	}
	else if (this.characterStream != null) {
		return this.characterStream;
	}
	else {
		return new InputStreamReader(
				(this.asciiStream != null ? this.asciiStream : StreamUtils.emptyInput()),
				StandardCharsets.US_ASCII);
	}
}
 
Example 7
Source File: PassThroughBlob.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public InputStream getBinaryStream() throws SQLException {
	if (this.content != null) {
		return new ByteArrayInputStream(this.content);
	}
	else {
		return (this.binaryStream != null ? this.binaryStream : StreamUtils.emptyInput());
	}
}
 
Example 8
Source File: CommonsMultipartFile.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Override
public InputStream getInputStream() throws IOException {
	if (!isAvailable()) {
		throw new IllegalStateException("File has been moved - cannot be read again");
	}
	InputStream inputStream = this.fileItem.getInputStream();
	return (inputStream != null ? inputStream : StreamUtils.emptyInput());
}
 
Example 9
Source File: Jaxb2CollectionHttpMessageConverter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object resolveEntity(String publicID, String systemID, String base, String ns) {
	return StreamUtils.emptyInput();
}
 
Example 10
Source File: AbstractMessageConverterMethodArgumentResolver.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() {
	return (this.body != null ? this.body : StreamUtils.emptyInput());
}
 
Example 11
Source File: SourceHttpMessageConverter.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public Object resolveEntity(String publicID, String systemID, String base, String ns) {
	return StreamUtils.emptyInput();
}
 
Example 12
Source File: OkHttp3ClientHttpResponse.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	ResponseBody body = this.response.body();
	return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
 
Example 13
Source File: HttpComponentsClientHttpResponse.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	HttpEntity entity = this.httpResponse.getEntity();
	return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
}
 
Example 14
Source File: OkHttp3ClientHttpResponse.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	ResponseBody body = this.response.body();
	return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
 
Example 15
Source File: AbstractMessageConverterMethodArgumentResolver.java    From java-technology-stack with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() {
	return (this.body != null ? this.body : StreamUtils.emptyInput());
}
 
Example 16
Source File: HttpComponentsAsyncClientHttpResponse.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	HttpEntity entity = this.httpResponse.getEntity();
	return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
}
 
Example 17
Source File: Jaxb2CollectionHttpMessageConverter.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public Object resolveEntity(String publicID, String systemID, String base, String ns) {
	return StreamUtils.emptyInput();
}
 
Example 18
Source File: OkHttp3ClientHttpResponse.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	ResponseBody body = this.response.body();
	return (body != null ? body.byteStream() : StreamUtils.emptyInput());
}
 
Example 19
Source File: HttpComponentsClientHttpResponse.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	HttpEntity entity = this.httpResponse.getEntity();
	return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
}
 
Example 20
Source File: HttpComponentsClientHttpResponse.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public InputStream getBody() throws IOException {
	HttpEntity entity = this.httpResponse.getEntity();
	return (entity != null ? entity.getContent() : StreamUtils.emptyInput());
}