首页>代码>java调用C程序转换spe录音文件为可播放的wav格式以及XML文件>/src/main/java/com/example/demo/utils/StreamGobbler.java
package com.example.demo.utils;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;

/**
 * @Author: YafengLiang
 * @Description:
 * @Date: Created in  9:56 2018/12/20
 */

public class StreamGobbler extends Thread {
    InputStream is;
    String type;
    OutputStream os;
    protected static final Logger logger = LoggerFactory.getLogger(StreamGobbler.class);

    public StreamGobbler(InputStream is, String type) {
        this(is, type, null);
    }

    StreamGobbler(InputStream is, String type, OutputStream redirect) {
        this.is = is;
        this.type = type;
        this.os = redirect;
    }

    public void run() {
        InputStreamReader isr = null;
        BufferedReader br = null;
        PrintWriter pw = null;
        try {
            if (os != null) {
                pw = new PrintWriter(os);
            }
            isr = new InputStreamReader(is);
            br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                if (pw != null){
                    pw.println(line);
                }
                logger.info(type + ">" + line);
            }

            if (pw != null) {
                pw.flush();
            }
        } catch (IOException ioe) {
            logger.error(ioe.getMessage());
            ioe.printStackTrace();
        } finally {
            try {
                if (pw != null) {
                    pw.close();
                }
                if (br != null) {
                    br.close();
                }
                if (isr != null) {
                    isr.close();
                }
            } catch (IOException e) {
                logger.error(e.getMessage());
                e.printStackTrace();
            }
        }
    }
}
最近下载更多
xiaobingb  LV4 2020年6月6日
最代码官方  LV167 2018年12月21日
最近浏览更多
uid0901  LV2 3月20日
funcrit  LV2 2022年7月22日
zhengling22  LV4 2021年6月28日
pxqtsht  LV15 2020年11月12日
asd45211  LV9 2020年6月10日
xiaobingb  LV4 2020年6月6日
加油干阳神  LV8 2020年5月13日
yiyigun 2020年2月18日
暂无贡献等级
wei112233  LV15 2020年2月2日
小王wang  LV10 2019年12月25日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友