Java Code Examples for org.springframework.util.FastByteArrayOutputStream

The following examples show how to use org.springframework.util.FastByteArrayOutputStream. These examples are extracted from open source projects. 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
@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 Project: sophia_scaffolding   Source File: ImageCodeHandler.java    License: 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 Project: sophia_scaffolding   Source File: ImageCodeHandler.java    License: 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
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
@Override
public FastByteArrayOutputStream getBody() throws IOException {
	return outputStream;
}
 
Example 6
Source Project: mica   Source File: ICaptchaService.java    License: 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 Project: mica   Source File: ICaptchaService.java    License: 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());
}