use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class Gzip method gzip.
/**
* 将普通数据流压缩
*
* @return Gzip
*/
public Gzip gzip() {
try {
target = (target instanceof GZIPOutputStream) ? (GZIPOutputStream) target : new GZIPOutputStream(target);
IoUtil.copy(source, target);
((GZIPOutputStream) target).finish();
} catch (IOException e) {
throw new IORuntimeException(e);
}
return this;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class ZipReader method get.
/**
* 获取指定路径的文件流<br>
* 如果是文件模式,则直接获取Entry对应的流,如果是流模式,则遍历entry后,找到对应流返回
*
* @param path 路径
* @return 文件流
*/
public InputStream get(String path) {
if (null != this.zipFile) {
final ZipFile zipFile = this.zipFile;
final ZipEntry entry = zipFile.getEntry(path);
if (null != entry) {
return ZipUtil.getStream(zipFile, entry);
}
} else {
try {
this.in.reset();
ZipEntry zipEntry;
while (null != (zipEntry = in.getNextEntry())) {
if (zipEntry.getName().equals(path)) {
return this.in;
}
}
} catch (IOException e) {
throw new IORuntimeException(e);
}
}
return null;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class Word07Writer method addPicture.
/**
* 增加图片,单独成段落,增加后图片流关闭
*
* @param in 图片流
* @param picType 图片类型,见Document.PICTURE_TYPE_XXX
* @param fileName 文件名
* @param width 宽度
* @param height 高度
* @param align 图片的对齐方式
* @return this
* @since 5.2.4
*/
public Word07Writer addPicture(InputStream in, PicType picType, String fileName, int width, int height, ParagraphAlignment align) {
final XWPFParagraph paragraph = doc.createParagraph();
paragraph.setAlignment(align);
final XWPFRun run = paragraph.createRun();
try {
run.addPicture(in, picType.getValue(), fileName, Units.toEMU(width), Units.toEMU(height));
} catch (InvalidFormatException e) {
throw new POIException(e);
} catch (IOException e) {
throw new IORuntimeException(e);
} finally {
IoUtil.close(in);
}
return this;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class AioClient method createChannel.
// ------------------------------------------------------------------------------------- Private method start
/**
* 初始化
*
* @param address 地址和端口
* @param poolSize 线程池大小
* @return this
*/
private static AsynchronousSocketChannel createChannel(InetSocketAddress address, int poolSize) {
AsynchronousSocketChannel channel;
try {
AsynchronousChannelGroup group = //
AsynchronousChannelGroup.withFixedThreadPool(// 默认线程池大小
poolSize, //
ThreadFactoryBuilder.create().setNamePrefix("Huool-socket-").build());
channel = AsynchronousSocketChannel.open(group);
} catch (IOException e) {
throw new IORuntimeException(e);
}
try {
channel.connect(address).get();
} catch (InterruptedException | ExecutionException e) {
IoUtil.close(channel);
throw new SocketRuntimeException(e);
}
return channel;
}
use of cn.hutool.core.io.IORuntimeException in project hutool by looly.
the class NioServer method init.
/**
* 初始化
*
* @param address 地址和端口
* @return this
*/
public NioServer init(InetSocketAddress address) {
try {
// 打开服务器套接字通道
this.serverSocketChannel = ServerSocketChannel.open();
// 设置为非阻塞状态
this.serverSocketChannel.configureBlocking(false);
// 绑定端口号
this.serverSocketChannel.bind(address);
// 打开一个选择器
this.selector = Selector.open();
// 服务器套接字注册到Selector中 并指定Selector监控连接事件
this.serverSocketChannel.register(selector, SelectionKey.OP_ACCEPT);
} catch (IOException e) {
throw new IORuntimeException(e);
}
log.debug("Server listen on: [{}]...", address);
return this;
}
Aggregations