/*
 * Decompiled with CFR 0.152.
 * 
 * Could not load the following classes:
 *  javax.microedition.io.Connection
 *  javax.microedition.io.Connector
 *  javax.microedition.io.file.FileConnection
 *  javax.microedition.midlet.MIDlet
 */
import java.io.DataInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.Vector;
import javax.microedition.io.Connection;
import javax.microedition.io.Connector;
import javax.microedition.io.file.FileConnection;
import javax.microedition.midlet.MIDlet;

/*
 * Duplicate member names - consider using --renamedupmembers true
 */
public final class fz
implements aa {
    private final String a;
    private final aa b;

    public final void a() {
        this.b.a();
    }

    public final void h() {
        this.b.h();
    }

    public final byte[] g(String string) {
        return this.b.g(string);
    }

    public final boolean a(String string, byte[] byArray) {
        return this.b.a(string, byArray);
    }

    public fz(String string, aa aa2) {
        this.b = aa2;
        this.a = string;
    }

    public static int b(MIDlet mIDlet) {
        int n = mIDlet.checkPermission("javax.microedition.io.Connector.file.read");
        int n2 = mIDlet.checkPermission("javax.microedition.io.Connector.file.write");
        if (n == 1 && n2 == 1) {
            return 1;
        }
        if (n != 0 && n2 != 0) {
            return -1;
        }
        return 0;
    }

    public static boolean a(MIDlet mIDlet) {
        return System.getProperty("microedition.io.file.FileConnection.version") != null && fz.b(mIDlet) != 0;
    }

    private static String h(String string) {
        if (string.indexOf(47) != -1) {
            string = ed.b(ed.a(string, '/'), '_');
        }
        return "ds" + string;
    }

    public final int b(byte[] byArray, String string) {
        try {
            return this.a(byArray, string);
        }
        catch (dd dd2) {
            return dd2.a;
        }
    }

    public final boolean b(String string) {
        try {
            this.f(string);
            return true;
        }
        catch (dd dd2) {
            return false;
        }
    }

    public final void c(String string) {
        try {
            FileConnection fileConnection = (FileConnection)Connector.open((String)this.a, (int)3);
            Enumeration enumeration = fileConnection.list("ds" + string + "*", false);
            while (enumeration.hasMoreElements()) {
                FileConnection fileConnection2 = (FileConnection)Connector.open((String)(this.a + enumeration.nextElement()), (int)3);
                fileConnection2.delete();
                fileConnection2.close();
            }
            fileConnection.close();
            return;
        }
        catch (IOException iOException) {
            return;
        }
    }

    public final int e(String string) {
        int n;
        FileConnection fileConnection;
        block3: {
            string = fz.h(string);
            FileConnection fileConnection2 = null;
            try {
                fileConnection2 = fileConnection = (FileConnection)Connector.open((String)(this.a + string), (int)1);
                long l = fileConnection.fileSize();
                n = (int)l;
                if (l <= (long)n) break block3;
                n = Integer.MAX_VALUE;
            }
            catch (IOException iOException) {
                pj.a(fileConnection2);
                return -1;
            }
            catch (Throwable throwable) {
                pj.a(fileConnection2);
                throw throwable;
            }
        }
        pj.a((Connection)fileConnection);
        return n;
    }

    public final int a(byte[] byArray, String string) {
        block9: {
            FileConnection fileConnection;
            block8: {
                string = fz.h(string);
                if (byArray == null) {
                    byArray = new byte[]{};
                }
                FileConnection fileConnection2 = null;
                try {
                    try {
                        fileConnection2 = fileConnection = (FileConnection)Connector.open((String)(this.a + string), (int)3);
                        if (fileConnection.exists()) {
                            fileConnection.delete();
                        }
                        fileConnection.create();
                        OutputStream outputStream = fileConnection.openOutputStream();
                        outputStream.write(byArray);
                        outputStream.close();
                        break block8;
                    }
                    catch (IOException iOException) {
                        if (fileConnection2 != null) {
                            dd dd2;
                            string = iOException.getMessage();
                            int n = fileConnection2.availableSize() >= (long)byArray.length ? -1 : -2;
                            dd dd3 = dd2;
                            dd3(string, n);
                            throw dd3;
                        }
                    }
                    catch (IllegalArgumentException illegalArgumentException) {
                        throw new dd(illegalArgumentException.getMessage(), -1);
                    }
                }
                catch (Throwable throwable) {
                    pj.a(fileConnection2);
                    throw throwable;
                }
                pj.a(fileConnection2);
                break block9;
            }
            pj.a((Connection)fileConnection);
        }
        return byArray.length;
    }

    public final void f(String string) {
        FileConnection fileConnection;
        FileConnection fileConnection2 = null;
        string = fz.h(string);
        try {
            try {
                fileConnection2 = fileConnection = (FileConnection)Connector.open((String)(this.a + string), (int)3);
                if (fileConnection.exists()) {
                    fileConnection.delete();
                }
            }
            catch (IOException iOException) {
                throw new dd(iOException.getMessage(), -1);
            }
        }
        catch (Throwable throwable) {
            pj.a(fileConnection2);
            throw throwable;
        }
        pj.a((Connection)fileConnection);
    }

    public final byte[] d(String string) {
        byte[] byArray;
        FileConnection fileConnection;
        block5: {
            FileConnection fileConnection2 = null;
            byte[] byArray2 = null;
            string = fz.h(string);
            try {
                fileConnection2 = fileConnection = (FileConnection)Connector.open((String)(this.a + string), (int)1);
                if (fileConnection.exists()) {
                    DataInputStream dataInputStream = fileConnection.openDataInputStream();
                    byArray2 = byArray = new byte[(int)fileConnection.fileSize()];
                    dataInputStream.readFully(byArray);
                    dataInputStream.close();
                    break block5;
                }
                byArray = null;
            }
            catch (IllegalArgumentException illegalArgumentException) {
                pj.a(fileConnection2);
                return byArray2;
            }
            catch (Throwable throwable) {
                pj.a(fileConnection2);
                throw throwable;
            }
            catch (IOException iOException) {
                pj.a(fileConnection2);
                return byArray2;
            }
        }
        pj.a((Connection)fileConnection);
        return byArray;
    }

    public final String[] f(String string) {
        String[] stringArray;
        FileConnection fileConnection;
        block5: {
            Object[] objectArray;
            FileConnection fileConnection2;
            fileConnection = null;
            try {
                try {
                    fileConnection = fileConnection2 = (FileConnection)Connector.open((String)this.a, (int)1);
                    Enumeration enumeration = fileConnection2.list("ds" + string + "*", false);
                    Vector<String> vector = new Vector<String>();
                    while (enumeration != null && enumeration.hasMoreElements()) {
                        vector.addElement(((String)enumeration.nextElement()).substring("ds".length()));
                    }
                    objectArray = new String[vector.size()];
                    vector.copyInto(objectArray);
                }
                catch (IOException iOException) {
                    stringArray = new String[]{};
                    break block5;
                }
            }
            catch (Throwable throwable) {
                pj.a(fileConnection);
                throw throwable;
            }
            pj.a((Connection)fileConnection2);
            return objectArray;
        }
        pj.a((Connection)fileConnection);
        return stringArray;
    }

    /*
     * Exception decompiling
     */
    public static String a(MIDlet var0, String var1_1) {
        /*
         * This method has failed to decompile.  When submitting a bug report, please provide this stack trace, and (if you hold appropriate legal rights) the relevant class file.
         * 
         * org.benf.cfr.reader.util.ConfusedCFRException: Back jump on a try block [egrp 0[TRYBLOCK] [3, 2 : 19->522)] java.lang.Exception
         *     at org.benf.cfr.reader.bytecode.analysis.opgraph.Op02WithProcessedDataAndRefs.insertExceptionBlocks(Op02WithProcessedDataAndRefs.java:2283)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisInner(CodeAnalyser.java:415)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysisOrWrapFail(CodeAnalyser.java:278)
         *     at org.benf.cfr.reader.bytecode.CodeAnalyser.getAnalysis(CodeAnalyser.java:201)
         *     at org.benf.cfr.reader.entities.attributes.AttributeCode.analyse(AttributeCode.java:94)
         *     at org.benf.cfr.reader.entities.Method.analyse(Method.java:531)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseMid(ClassFile.java:1055)
         *     at org.benf.cfr.reader.entities.ClassFile.analyseTop(ClassFile.java:942)
         *     at org.benf.cfr.reader.Driver.doJarVersionTypes(Driver.java:257)
         *     at org.benf.cfr.reader.Driver.doJar(Driver.java:139)
         *     at org.benf.cfr.reader.CfrDriverImpl.analyse(CfrDriverImpl.java:76)
         *     at org.benf.cfr.reader.Main.main(Main.java:54)
         */
        throw new IllegalStateException("Decompilation failed");
    }
}

