org.springframework.util.FastByteArrayOutputStream源码实例Demo

类org.springframework.util.FastByteArrayOutputStream源码实例Demo

下面列出了org.springframework.util.FastByteArrayOutputStream 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: smaker   文件: ImageCodeHandler.java
@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())));
}
 
源代码2 项目: sophia_scaffolding   文件: ImageCodeHandler.java
@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())));
}
 
源代码3 项目: sophia_scaffolding   文件: ImageCodeHandler.java
@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())));
}
 
源代码4 项目: mica   文件: InMemoryJavaCompiler.java
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();
}
 
@Override
public FastByteArrayOutputStream getBody() throws IOException {
	return outputStream;
}
 
源代码6 项目: mica   文件: ICaptchaService.java
/**
 * 生成验证码
 *
 * @param uuid 自定义缓存的 uuid
 * @return bytes
 */
default byte[] generateBytes(String uuid) {
	FastByteArrayOutputStream outputStream = new FastByteArrayOutputStream();
	this.generate(uuid, outputStream);
	return outputStream.toByteArray();
}
 
源代码7 项目: mica   文件: ICaptchaService.java
/**
 * 生成验证码 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());
}
 
源代码评论
动弹
沙发等你来抢
 类所在包
 类方法
 同包方法