/*
 * Decompiled with CFR 0.152.
 */
package com.hst.test;

import com.hst.common.util.Base64;
import com.hst.common.util.DBConnectUtil;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.Scanner;

public class ExportJpg {
    public static void main(String[] args) throws Exception {
        Connection conn = null;
        Statement ps = null;
        ResultSet rs = null;
        try {
            try {
                conn = DBConnectUtil.getConnection(" jdbc:oracle:thin:@192.168.10.2:1521:TAX", "ssgladmin", "ssgladmin", "oracle.jdbc.driver.OracleDriver");
                String sql = "SELECT sfzzm_pic,head_pic,sfzhm FROM TM.SMZ_BSY_RXSFZ_BDJL  WHERE ROWNUM<10 ORDER BY rxsfz_bdxh DESC";
                ps = conn.prepareStatement(sql);
                rs = ps.executeQuery();
                while (rs.next()) {
                    String sfzhm = rs.getString(3);
                    InputStream sfzzmpic = rs.getAsciiStream(1);
                    InputStream headPic = rs.getAsciiStream(2);
                    ExportJpg.exportJpg(sfzzmpic, "S" + sfzhm + ".jpg");
                    ExportJpg.exportJpg(headPic, "R" + sfzhm + ".jpg");
                }
            }
            catch (Exception e) {
                conn.rollback();
                e.printStackTrace();
                throw e;
            }
        }
        finally {
            if (rs != null) {
                rs.close();
            }
            if (ps != null) {
                ps.close();
            }
            if (conn != null) {
                conn.close();
            }
        }
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    private static void exportJpg(InputStream ins, String fileName) throws Exception {
        FilterOutputStream bosInst = null;
        byte[] cfr_ignored_0 = new byte[0x100000];
        String path = "D:\\head\\";
        try {
            try {
                File file = new File(String.valueOf(path) + fileName);
                if (file.isFile() && file.exists()) {
                    file.delete();
                }
                bosInst = new BufferedOutputStream(new FileOutputStream(String.valueOf(path) + fileName));
                StringBuffer base64 = new StringBuffer();
                Scanner scan = new Scanner(ins);
                scan.useDelimiter("\r\n");
                while (scan.hasNext()) {
                    base64.append(scan.next()).append("");
                }
                byte[] bytes = Base64.stringToByte(base64.toString());
                bosInst.write(bytes);
                ((BufferedOutputStream)bosInst).flush();
                return;
            }
            catch (FileNotFoundException e) {
                e.printStackTrace();
                if (bosInst == null) return;
                try {
                    bosInst.close();
                    return;
                }
                catch (IOException e2) {
                    e2.printStackTrace();
                }
                return;
            }
            catch (IOException e) {
                e.printStackTrace();
                if (bosInst == null) return;
                try {
                    bosInst.close();
                    return;
                }
                catch (IOException e3) {
                    e3.printStackTrace();
                }
                return;
            }
        }
        finally {
            if (bosInst != null) {
                try {
                    bosInst.close();
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
