Search in sources :

Example 76 with IORuntimeException

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;
}
Also used : IORuntimeException(cn.hutool.core.io.IORuntimeException) GZIPOutputStream(java.util.zip.GZIPOutputStream) IOException(java.io.IOException)

Example 77 with IORuntimeException

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;
}
Also used : ZipFile(java.util.zip.ZipFile) IORuntimeException(cn.hutool.core.io.IORuntimeException) ZipEntry(java.util.zip.ZipEntry) IOException(java.io.IOException)

Example 78 with IORuntimeException

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;
}
Also used : XWPFParagraph(org.apache.poi.xwpf.usermodel.XWPFParagraph) XWPFRun(org.apache.poi.xwpf.usermodel.XWPFRun) IORuntimeException(cn.hutool.core.io.IORuntimeException) IOException(java.io.IOException) InvalidFormatException(org.apache.poi.openxml4j.exceptions.InvalidFormatException) POIException(cn.hutool.poi.exceptions.POIException)

Example 79 with IORuntimeException

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;
}
Also used : AsynchronousSocketChannel(java.nio.channels.AsynchronousSocketChannel) IORuntimeException(cn.hutool.core.io.IORuntimeException) AsynchronousChannelGroup(java.nio.channels.AsynchronousChannelGroup) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) SocketRuntimeException(cn.hutool.socket.SocketRuntimeException)

Example 80 with IORuntimeException

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;
}
Also used : IORuntimeException(cn.hutool.core.io.IORuntimeException) IOException(java.io.IOException)

Aggregations

IORuntimeException (cn.hutool.core.io.IORuntimeException)81 IOException (java.io.IOException)75 File (java.io.File)9 StreamProgress (cn.hutool.core.io.StreamProgress)4 FileOutputStream (java.io.FileOutputStream)4 InputStream (java.io.InputStream)4 OutputStream (java.io.OutputStream)4 UtilException (cn.hutool.core.exceptions.UtilException)3 POIException (cn.hutool.poi.exceptions.POIException)3 Rectangle (java.awt.Rectangle)3 BufferedImage (java.awt.image.BufferedImage)3 BufferedReader (java.io.BufferedReader)3 SocketChannel (java.nio.channels.SocketChannel)3 Path (java.nio.file.Path)3 Test (org.junit.Test)3 StreamGobbler (ch.ethz.ssh2.StreamGobbler)2 CryptoException (cn.hutool.crypto.CryptoException)2 RenderedImage (java.awt.image.RenderedImage)2 BufferedWriter (java.io.BufferedWriter)2 FileInputStream (java.io.FileInputStream)2