org.springframework.util.FastByteArrayOutputStream Java Examples

The following examples show how to use org.springframework.util.FastByteArrayOutputStream. 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: ImageCodeHandler.java    From smaker with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
	//生成验证码
	String text = producer.createText();
	BufferedImage image = producer.createImage(text);

	//保存验证码信息
	String randomStr = serverRequest.queryParam("randomStr").get();
	redisTemplate.opsForValue().set(CommonConstants.DEFAULT_CODE_KEY + randomStr, text, 60, TimeUnit.SECONDS);

	// 转换流信息写出
	FastByteArrayOutputStream os = new FastByteArrayOutputStream();
	try {
		ImageIO.write(image, "jpeg", os);
	} catch (IOException e) {
		log.error("ImageIO write err", e);
		return Mono.error(e);
	}

	return ServerResponse
		.status(HttpStatus.OK)
		.contentType(MediaType.IMAGE_JPEG)
		.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
}
 
Example #2
Source File: ImageCodeHandler.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
	//生成验证码
	String text = producer.createText();
	BufferedImage image = producer.createImage(text);

	//保存验证码信息
	String randomStr = serverRequest.queryParam("randomStr").get();
	redisTemplate.opsForValue().set(DEFAULT_CODE_KEY + randomStr, text, 120, TimeUnit.SECONDS);

	// 转换流信息写出
	FastByteArrayOutputStream os = new FastByteArrayOutputStream();
	try {
		ImageIO.write(image, "jpeg", os);
	} catch (IOException e) {
		log.error("ImageIO write err", e);
		return Mono.error(e);
	}

	return ServerResponse
		.status(HttpStatus.OK)
		.contentType(MediaType.IMAGE_JPEG)
		.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
}
 
Example #3
Source File: ImageCodeHandler.java    From sophia_scaffolding with Apache License 2.0 6 votes vote down vote up
@Override
public Mono<ServerResponse> handle(ServerRequest serverRequest) {
	//生成验证码
	String text = producer.createText();
	BufferedImage image = producer.createImage(text);

	//保存验证码信息
	String randomStr = serverRequest.queryParam("randomStr").get();
	redisTemplate.opsForValue().set(DEFAULT_CODE_KEY + randomStr, text, 120, TimeUnit.SECONDS);

	// 转换流信息写出
	FastByteArrayOutputStream os = new FastByteArrayOutputStream();
	try {
		ImageIO.write(image, "jpeg", os);
	} catch (IOException e) {
		log.error("ImageIO write err", e);
		return Mono.error(e);
	}

	return ServerResponse
		.status(HttpStatus.OK)
		.contentType(MediaType.IMAGE_JPEG)
		.body(BodyInserters.fromResource(new ByteArrayResource(os.toByteArray())));
}
 
Example #4
Source File: InMemoryJavaCompiler.java    From mica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public MemoryJavaFileObject(String className, CharSequence sourceCode) {
	super(URI.create("string:///" + className.replace(CharPool.DOT, CharPool.SLASH) + Kind.SOURCE.extension), Kind.SOURCE);
	this.className = className;
	this.sourceCode = sourceCode;
	this.byteCode = new FastByteArrayOutputStream();
}
 
Example #5
Source File: DubboHttpOutputMessage.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Override
public FastByteArrayOutputStream getBody() throws IOException {
	return outputStream;
}
 
Example #6
Source File: ICaptchaService.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 生成验证码
 *
 * @param uuid 自定义缓存的 uuid
 * @return bytes
 */
default byte[] generateBytes(String uuid) {
	FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream();
	this.generate(uuid, outputStream);
	return outputStream.toByteArray();
}
 
Example #7
Source File: ICaptchaService.java    From mica with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 生成验证码 base64 字符串
 *
 * @param uuid 自定义缓存的 uuid
 * @return base64 图片
 */
default String generateBase64(String uuid) {
	FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream();
	this.generate(uuid, outputStream);
	return "data:image/jpeg;base64," + Base64Util.encodeToString(outputStream.toByteArray());
}