use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class ImgUtil method write.
/**
* 通过{@link ImageWriter}写出图片到输出流
*
* @param image 图片
* @param writer {@link ImageWriter}
* @param output 输出的Image流{@link ImageOutputStream}
* @param quality 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩
* @return 是否成功写出
* @since 4.3.2
*/
public static boolean write(Image image, ImageWriter writer, ImageOutputStream output, float quality) {
if (writer == null) {
return false;
}
writer.setOutput(output);
final RenderedImage renderedImage = toRenderedImage(image);
// 设置质量
ImageWriteParam imgWriteParams = null;
if (quality > 0 && quality < 1) {
imgWriteParams = writer.getDefaultWriteParam();
if (imgWriteParams.canWriteCompressed()) {
imgWriteParams.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
imgWriteParams.setCompressionQuality(quality);
// ColorModel.getRGBdefault();
final ColorModel colorModel = renderedImage.getColorModel();
imgWriteParams.setDestinationType(new ImageTypeSpecifier(colorModel, colorModel.createCompatibleSampleModel(16, 16)));
}
}
try {
if (null != imgWriteParams) {
writer.write(null, new IIOImage(renderedImage, null, null), imgWriteParams);
} else {
writer.write(renderedImage);
}
output.flush();
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
writer.dispose();
}
return true;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class StrJoiner method append.
@Override
public StrJoiner append(CharSequence csq, int startInclude, int endExclude) {
if (null == csq) {
switch(this.nullMode) {
case IGNORE:
return this;
case TO_EMPTY:
csq = StrUtil.EMPTY;
break;
case NULL_STRING:
csq = StrUtil.NULL;
endExclude = StrUtil.NULL.length();
break;
}
}
try {
final Appendable appendable = prepare();
if (wrapElement && StrUtil.isNotEmpty(this.prefix)) {
appendable.append(prefix);
}
appendable.append(csq, startInclude, endExclude);
if (wrapElement && StrUtil.isNotEmpty(this.suffix)) {
appendable.append(suffix);
}
} catch (IOException e) {
throw new IORuntimeException(e);
}
return this;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class SmUtil method rsPlainToAsn1.
/**
* BC的SM3withSM2验签需要的rs是asn1格式的,这个方法将直接拼接r||s的字节数组转化成asn1格式
*
* @param sign in plain byte array
* @return rs result in asn1 format
* @since 4.5.0
*/
public static byte[] rsPlainToAsn1(byte[] sign) {
if (sign.length != RS_LEN * 2) {
throw new CryptoException("err rs. ");
}
BigInteger r = new BigInteger(1, Arrays.copyOfRange(sign, 0, RS_LEN));
BigInteger s = new BigInteger(1, Arrays.copyOfRange(sign, RS_LEN, RS_LEN * 2));
try {
return StandardDSAEncoding.INSTANCE.encode(SM2_DOMAIN_PARAMS.getN(), r, s);
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class SmUtil method rsAsn1ToPlain.
/**
* BC的SM3withSM2签名得到的结果的rs是asn1格式的,这个方法转化成直接拼接r||s
*
* @param rsDer rs in asn1 format
* @return sign result in plain byte array
* @since 4.5.0
*/
public static byte[] rsAsn1ToPlain(byte[] rsDer) {
final BigInteger[] decode;
try {
decode = StandardDSAEncoding.INSTANCE.decode(SM2_DOMAIN_PARAMS.getN(), rsDer);
} catch (IOException e) {
throw new IORuntimeException(e);
}
final byte[] r = bigIntToFixedLengthBytes(decode[0]);
final byte[] s = bigIntToFixedLengthBytes(decode[1]);
return ArrayUtil.addAll(r, s);
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class GlobalCookieManager method add.
/**
* 将本地存储的Cookie信息附带到Http请求中,不覆盖用户定义好的Cookie
*
* @param conn {@link HttpConnection}
*/
public static void add(HttpConnection conn) {
if (null == cookieManager) {
// 全局Cookie管理器关闭
return;
}
Map<String, List<String>> cookieHeader;
try {
cookieHeader = cookieManager.get(getURI(conn), new HashMap<>(0));
} catch (IOException e) {
throw new IORuntimeException(e);
}
// 不覆盖模式回填Cookie头,这样用户定义的Cookie将优先
conn.header(cookieHeader, false);
}
Aggregations