Example usage for java.io DataInputStream readUTF

List of usage examples for java.io DataInputStream readUTF

Introduction

In this page you can find the example usage for java.io DataInputStream readUTF.

Prototype

public final String readUTF() throws IOException 

Source Link

Document

See the general contract of the readUTF method of DataInput.

Usage

From source file:MiGA.StatsSelection.java

public void getPerfectSSRs(String[] organisms, int length, boolean flag)
        throws FileNotFoundException, SQLException, ClassNotFoundException, IOException {

    for (int i = 0; i < organisms.length; i++) {
        // 18/11/2013 added starting here
        String filetype = "";
        String filepro = "";

        if (flag) {
            filetype = "organisms";
            filepro = "organisms/" + organisms[i] + "/data/";
            int ret = getOrganismStatus(organisms[i]);
            if (ret == -1)
                indexer = new Indexer(chromosomelist);
            else//from w  ww  . j  a v a 2s .c o m
                indexer = new Indexer(ret);

        } else {
            filetype = "local";
            filepro = "local/" + organisms[i] + "/data/";
            String indexfile = "local/" + organisms[i] + "/index.txt";
            indexer = new Indexer(indexfile);
        }
        //List<String> files = getFiles(organisms[i], minlen, flag);

        // 18/11/2013 added ending here
        countmono.set(i, 0);
        countdi.set(i, 0);
        counttri.set(i, 0);
        counttetra.set(i, 0);
        countpenta.set(i, 0);
        counthexa.set(i, 0);
        countmonore.set(i, 0);
        countdire.set(i, 0);
        counttrire.set(i, 0);
        counttetrare.set(i, 0);
        countpentare.set(i, 0);
        counthexare.set(i, 0);
        Amono.set(i, 0);
        Adi.set(i, 0);
        Atri.set(i, 0);
        Atetra.set(i, 0);
        Apenta.set(i, 0);
        Ahexa.set(i, 0);
        Tmono.set(i, 0);
        Tdi.set(i, 0);
        Ttri.set(i, 0);
        Ttetra.set(i, 0);
        Tpenta.set(i, 0);
        Thexa.set(i, 0);
        Gmono.set(i, 0);
        Gdi.set(i, 0);
        Gtri.set(i, 0);
        Gtetra.set(i, 0);
        Gpenta.set(i, 0);
        Ghexa.set(i, 0);
        Cmono.set(i, 0);
        Cdi.set(i, 0);
        Ctri.set(i, 0);
        Ctetra.set(i, 0);
        Cpenta.set(i, 0);
        Chexa.set(i, 0);

        while (indexer.hasNext()) {
            String files = filepro + indexer.getNextFileName();
            //for (int j = 0; j < files.size(); j++) {

            List<File> exis = new ArrayList<File>();
            exis.add(new File(files + "_" + length + "_monoPerfect.temp"));
            exis.add(new File(files + "_" + length + "_diPerfect.temp"));
            exis.add(new File(files + "_" + length + "_triPerfect.temp"));
            exis.add(new File(files + "_" + length + "_tetraPerfect.temp"));
            exis.add(new File(files + "_" + length + "_pentaPerfect.temp"));
            exis.add(new File(files + "_" + length + "_hexaPerfect.temp"));
            int num = 0;
            for (int temp = 0; temp < exis.size(); temp++) {
                if (exis.get(temp).exists()) {
                    num++;
                }
            }

            if (num != exis.size()) {

                DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files)));

                //
                DataOutputStream outmono = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_monoPerfect.temp")));
                DataOutputStream outdi = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_diPerfect.temp")));
                DataOutputStream outtri = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_triPerfect.temp")));
                DataOutputStream outtetra = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_tetraPerfect.temp")));
                DataOutputStream outpenta = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_pentaPerfect.temp")));
                DataOutputStream outhexa = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_hexaPerfect.temp")));
                boolean eof = false;
                while (!eof) {
                    try {
                        int len = in.readInt();
                        int line = in.readInt();
                        for (int k = 0; k < len; k++) {
                            SSR.add(in.readUTF());
                            int end = in.readInt();
                            repeats.add(in.readInt());
                            EndOfSsr.add(end + (line - 1) * 20000);
                        }

                        for (int c = 0; c < SSR.size(); c++) {

                            if (!SSR.get(c).contains("N")) {
                                if (repeats.get(c) * SSR.get(c).length() >= length) {
                                    if (SSR.get(c).length() == 1) {
                                        countmono.set(i, countmono.get(i) + 1);
                                        countmonore.set(i, countmonore.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Amono.set(i, Amono.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Tmono.set(i, Tmono.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Gmono.set(i, Gmono.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Cmono.set(i, Cmono.get(i) + repeats.get(c));
                                        }
                                        outmono.writeUTF(SSR.get(c));
                                        outmono.writeInt(repeats.get(c));
                                        outmono.writeInt(EndOfSsr.get(c));
                                    } else if (SSR.get(c).length() == 2) {
                                        countdi.set(i, countdi.get(i) + 1);
                                        countdire.set(i, countdire.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Adi.set(i, Adi.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Tdi.set(i, Tdi.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Gdi.set(i, Gdi.get(i) + repeats.get(c));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Cdi.set(i, Cdi.get(i) + repeats.get(c));
                                        }
                                        outdi.writeUTF(SSR.get(c));
                                        outdi.writeInt(repeats.get(c));
                                        outdi.writeInt(EndOfSsr.get(c));
                                    } else if (SSR.get(c).length() == 3) {
                                        counttri.set(i, counttri.get(i) + 1);
                                        counttrire.set(i, counttrire.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Atri.set(i, Atri.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "A"));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Ttri.set(i, Ttri.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "T"));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Gtri.set(i, Gtri.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "G"));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Ctri.set(i, Ctri.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "C"));
                                        }
                                        outtri.writeUTF(SSR.get(c));
                                        outtri.writeInt(repeats.get(c));
                                        outtri.writeInt(EndOfSsr.get(c));
                                    } else if (SSR.get(c).length() == 4) {
                                        counttetra.set(i, counttetra.get(i) + 1);
                                        counttetrare.set(i, counttetrare.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Atetra.set(i, Atetra.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "A"));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Ttetra.set(i, Ttetra.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "T"));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Gtetra.set(i, Gtetra.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "G"));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Ctetra.set(i, Ctetra.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "C"));
                                        }
                                        outtetra.writeUTF(SSR.get(c));
                                        outtetra.writeInt(repeats.get(c));
                                        outtetra.writeInt(EndOfSsr.get(c));
                                    } else if (SSR.get(c).length() == 5) {

                                        countpenta.set(i, countpenta.get(i) + 1);
                                        countpentare.set(i, countpentare.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Apenta.set(i, Apenta.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "A"));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Tpenta.set(i, Tpenta.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "T"));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Gpenta.set(i, Gpenta.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "G"));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Cpenta.set(i, Cpenta.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "C"));
                                        }

                                        outpenta.writeUTF(SSR.get(c));
                                        outpenta.writeInt(repeats.get(c));
                                        outpenta.writeInt(EndOfSsr.get(c));
                                    } else if (SSR.get(c).length() == 6) {

                                        counthexa.set(i, counthexa.get(i) + 1);
                                        counthexare.set(i, counthexare.get(i) + repeats.get(c));
                                        if (SSR.get(c).contains("A")) {
                                            Ahexa.set(i, Ahexa.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "A"));
                                        }
                                        if (SSR.get(c).contains("T")) {
                                            Thexa.set(i, Thexa.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "T"));
                                        }
                                        if (SSR.get(c).contains("G")) {
                                            Ghexa.set(i, Ghexa.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "G"));
                                        }
                                        if (SSR.get(c).contains("C")) {
                                            Chexa.set(i, Chexa.get(i) + repeats.get(c)
                                                    * StringUtils.countMatches(SSR.get(c), "C"));
                                        }
                                        outhexa.writeUTF(SSR.get(c));
                                        outhexa.writeInt(repeats.get(c));
                                        outhexa.writeInt(EndOfSsr.get(c));
                                    }
                                }
                            }
                        }

                        SSR = new ArrayList<String>();
                        repeats = new ArrayList<Integer>();
                        EndOfSsr = new ArrayList<Integer>();

                    } catch (EOFException e) {
                        eof = true;
                    }
                }

                outmono.close();
                outdi.close();
                outtri.close();
                outtetra.close();
                outpenta.close();
                outhexa.close();

                //
                in.close();
                DataOutputStream save = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files.substring(0, files.lastIndexOf('/')) + "/perf_stats")));
                save.writeInt(countmono.get(i));
                save.writeInt(countdi.get(i));
                save.writeInt(counttri.get(i));
                save.writeInt(counttetra.get(i));
                save.writeInt(countpenta.get(i));
                save.writeInt(counthexa.get(i));
                save.writeInt(countmonore.get(i));
                save.writeInt(countdire.get(i));
                save.writeInt(counttrire.get(i));
                save.writeInt(counttetrare.get(i));
                save.writeInt(countpentare.get(i));
                save.writeInt(counthexare.get(i));
                save.writeInt(Amono.get(i));
                save.writeInt(Tmono.get(i));
                save.writeInt(Gmono.get(i));
                save.writeInt(Cmono.get(i));
                save.writeInt(Adi.get(i));
                save.writeInt(Tdi.get(i));
                save.writeInt(Gdi.get(i));
                save.writeInt(Cdi.get(i));
                save.writeInt(Atri.get(i));
                save.writeInt(Ttri.get(i));
                save.writeInt(Gtri.get(i));
                save.writeInt(Ctri.get(i));
                save.writeInt(Atetra.get(i));
                save.writeInt(Ttetra.get(i));
                save.writeInt(Gtetra.get(i));
                save.writeInt(Ctetra.get(i));
                save.writeInt(Apenta.get(i));
                save.writeInt(Tpenta.get(i));
                save.writeInt(Gpenta.get(i));
                save.writeInt(Cpenta.get(i));
                save.writeInt(Ahexa.get(i));
                save.writeInt(Thexa.get(i));
                save.writeInt(Ghexa.get(i));
                save.writeInt(Chexa.get(i));
                save.close();

            } else {
                DataInputStream save = new DataInputStream(new BufferedInputStream(
                        new FileInputStream(files.substring(0, files.lastIndexOf('/')) + "/perf_stats")));

                countmono.set(i, save.readInt());
                countdi.set(i, save.readInt());
                counttri.set(i, save.readInt());
                counttetra.set(i, save.readInt());
                countpenta.set(i, save.readInt());
                counthexa.set(i, save.readInt());
                countmonore.set(i, save.readInt());
                countdire.set(i, save.readInt());
                counttrire.set(i, save.readInt());
                counttetrare.set(i, save.readInt());
                countpentare.set(i, save.readInt());
                counthexare.set(i, save.readInt());
                Amono.set(i, save.readInt());
                Tmono.set(i, save.readInt());
                Gmono.set(i, save.readInt());
                Cmono.set(i, save.readInt());
                Adi.set(i, save.readInt());
                Tdi.set(i, save.readInt());
                Gdi.set(i, save.readInt());
                Cdi.set(i, save.readInt());
                Atri.set(i, save.readInt());
                Ttri.set(i, save.readInt());
                Gtri.set(i, save.readInt());
                Ctri.set(i, save.readInt());
                Atetra.set(i, save.readInt());
                Ttetra.set(i, save.readInt());
                Gtetra.set(i, save.readInt());
                Ctetra.set(i, save.readInt());
                Apenta.set(i, save.readInt());
                Tpenta.set(i, save.readInt());
                Gpenta.set(i, save.readInt());
                Cpenta.set(i, save.readInt());
                Ahexa.set(i, save.readInt());
                Thexa.set(i, save.readInt());
                Ghexa.set(i, save.readInt());
                Chexa.set(i, save.readInt());
                save.close();
            }
        }
    }
}

From source file:MiGA.StatsSelection.java

public void getImPerfectSSRs(String[] organisms, int length, boolean flag, int gap)
        throws SQLException, ClassNotFoundException, FileNotFoundException, IOException {

    for (int i = 0; i < organisms.length; i++) {

        countmono.set(i, 0);//from www.j a v  a  2s .c  o  m
        countdi.set(i, 0);
        counttri.set(i, 0);
        counttetra.set(i, 0);
        countpenta.set(i, 0);
        counthexa.set(i, 0);
        countmonore.set(i, 0);
        countdire.set(i, 0);
        counttrire.set(i, 0);
        counttetrare.set(i, 0);
        countpentare.set(i, 0);
        counthexare.set(i, 0);
        Amono.set(i, 0);
        Adi.set(i, 0);
        Atri.set(i, 0);
        Atetra.set(i, 0);
        Apenta.set(i, 0);
        Ahexa.set(i, 0);
        Tmono.set(i, 0);
        Tdi.set(i, 0);
        Ttri.set(i, 0);
        Ttetra.set(i, 0);
        Tpenta.set(i, 0);
        Thexa.set(i, 0);
        Gmono.set(i, 0);
        Gdi.set(i, 0);
        Gtri.set(i, 0);
        Gtetra.set(i, 0);
        Gpenta.set(i, 0);
        Ghexa.set(i, 0);
        Cmono.set(i, 0);
        Cdi.set(i, 0);
        Ctri.set(i, 0);
        Ctetra.set(i, 0);
        Cpenta.set(i, 0);
        Chexa.set(i, 0);

        boolean found = false;
        String buffer = new String();
        int seekstart = 0;
        int seekend = 0;
        List<String> ssrs = new ArrayList<String>();
        // 18/11/2013 added starting here
        String filetype = "";
        String filepro = "";

        if (flag) {
            filetype = "organisms";
            filepro = "organisms/" + organisms[i] + "/data/";
            int ret = getOrganismStatus(organisms[i]);
            if (ret == -1)
                indexer = new Indexer(chromosomelist);
            else
                indexer = new Indexer(ret);

        } else {
            filetype = "local";
            filepro = "local/" + organisms[i] + "/data/";
            String indexfile = "local/" + organisms[i] + "/index.txt";
            indexer = new Indexer(indexfile);
        }
        //List<String> files = getFiles(organisms[i], minlen, flag);

        // 18/11/2013 added ending here
        while (indexer.hasNext()) {
            String files = filepro + indexer.getNextFileName();

            List<File> exis = new ArrayList<File>();
            exis.add(new File(files + "_" + length + "_" + gap + "_monoImPerfect.temp"));
            exis.add(new File(files + "_" + length + "_" + gap + "_diImPerfect.temp"));
            exis.add(new File(files + "_" + length + "_" + gap + "_triImPerfect.temp"));
            exis.add(new File(files + "_" + length + "_" + gap + "_tetraImPerfect.temp"));
            exis.add(new File(files + "_" + length + "_" + gap + "_pentaImPerfect.temp"));
            exis.add(new File(files + "_" + length + "_" + gap + "_hexaImPerfect.temp"));
            int num = 0;
            for (int temp = 0; temp < exis.size(); temp++) {
                if (exis.get(temp).exists()) {
                    num++;
                }
            }

            if (num != exis.size()) {

                DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(files)));
                DataOutputStream outmono = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_monoImPerfect.temp")));
                DataOutputStream outdi = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_diImPerfect.temp")));
                DataOutputStream outtri = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_triImPerfect.temp")));
                DataOutputStream outtetra = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_tetraImPerfect.temp")));
                DataOutputStream outpenta = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_pentaImPerfect.temp")));
                DataOutputStream outhexa = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files + "_" + length + "_" + gap + "_hexaImPerfect.temp")));
                boolean eof = false;
                while (!eof) {
                    try {
                        SSR = new ArrayList<String>();
                        repeats = new ArrayList<Integer>();
                        EndOfSsr = new ArrayList<Integer>();
                        start = new ArrayList<Integer>();

                        int len = in.readInt();
                        int line = in.readInt();
                        //try{
                        for (int k = 0; k < len; k++) {
                            String temp = in.readUTF();
                            //THIS
                            //if(!temp.contains("N")){
                            SSR.add(temp);
                            EndOfSsr.add(in.readInt());
                            repeats.add(in.readInt());
                            start.add(EndOfSsr.get(k) - (SSR.get(k).length() * repeats.get(k)));
                            /*}else{
                                int junk = in.readInt();
                                junk = in.readInt();
                                k--;
                                len--;
                            }*/
                        }
                        /*}
                        catch(IndexOutOfBoundsException e){
                        System.out.println(SSR.size());
                        System.out.println(EndOfSsr.size());
                        System.out.println(repeats.size());
                        System.out.println(start.size());
                        }*/

                        List<String> SSRlen = new ArrayList<String>();
                        List<Integer> Endlen = new ArrayList<Integer>();
                        List<Integer> repslen = new ArrayList<Integer>();
                        List<Integer> startlen = new ArrayList<Integer>();

                        for (int k = 0; k < SSR.size(); k++) {
                            if (SSR.get(k).length() * repeats.get(k) >= length) {
                                SSRlen.add(SSR.get(k));
                                Endlen.add(EndOfSsr.get(k));
                                repslen.add(repeats.get(k));
                                startlen.add(start.get(k));
                            }
                        }

                        List<Integer> sortedstart = new ArrayList<Integer>();

                        List<Integer> sortedend = new ArrayList<Integer>();
                        for (int t = 0; t < startlen.size(); t++) {
                            sortedstart.add(startlen.get(t));
                            sortedend.add(Endlen.get(t));
                        }

                        Collections.sort(sortedstart);
                        Collections.sort(sortedend);

                        //List<String> tofile = new ArrayList<String>();
                        for (int k = 0; k < sortedstart.size() - 1; k++) {
                            found = false;
                            ssrs.clear();
                            ssrs = new ArrayList<String>();
                            if (sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                    && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                                seekstart = sortedstart.get(k);
                                while (k < sortedstart.size() - 1
                                        && sortedstart.get(k + 1) - sortedend.get(k) <= gap
                                        && sortedstart.get(k + 1) - sortedend.get(k) >= 0) {
                                    for (int c = 0; c < startlen.size(); c++) {
                                        if (sortedstart.get(k) == startlen.get(c)) {
                                            ssrs.add(SSRlen.get(c));
                                        }
                                        if (sortedstart.get(k + 1) == startlen.get(c)) {
                                            ssrs.add(SSRlen.get(c));
                                            seekend = Endlen.get(c);
                                            found = true;
                                        }
                                    }
                                    k++;
                                }
                                k--;
                            }
                            boolean check = checkallsame(ssrs);
                            if (found && check) {
                                BufferedReader stdin = null;
                                if (flag) {
                                    String[] temp = files.split("/");
                                    boolean type = CheckForKaryotype(organisms[i]);
                                    String newdir = "";
                                    if (type) {
                                        newdir = temp[0] + "/" + temp[1] + "/chrom-"
                                                + temp[3].substring(0, temp[3].lastIndexOf('.'))
                                                + "-slices.txt";
                                    } else {
                                        newdir = temp[0] + "/" + temp[1] + "/slice-"
                                                + temp[3].substring(0, temp[3].lastIndexOf('.')) + ".txt";
                                    }

                                    stdin = new BufferedReader(new FileReader(newdir));
                                } else {
                                    //files.add("local/" + organism + "/data/" + temp + ".ssr");
                                    String[] temp = files.split("data/");
                                    String newdir = temp[0] + "/"
                                            + temp[1].substring(0, temp[1].lastIndexOf('.')) + ".txt";
                                    stdin = new BufferedReader(new FileReader(newdir));
                                }
                                buffer = "";
                                for (int c = 0; c < line; c++) {
                                    buffer = stdin.readLine();
                                }
                                //System.out.println(buffer.length() + "\t" + seekstart + "\t" + seekend);
                                int real_end = ((Integer) (line - 1) * 20000) + seekend;
                                int real_start = ((Integer) (line - 1) * 20000) + seekstart;
                                //tofile.add("SSR: "+buffer.substring(seekstart, seekend) + "start-end: "+ real_start + "-" +real_end );

                                if (ssrs.get(1).length() == 1) {
                                    countmono.set(i, countmono.get(i) + 1);
                                    countmonore.set(i, countmonore.get(i) + real_end - real_start);
                                    outmono.writeUTF(buffer.substring(seekstart + 1, seekend + 1));
                                    if (buffer.substring(seekstart + 1, seekend + 1).contains("A")
                                            || buffer.substring(seekstart + 1, seekend + 1).contains("a")) {
                                        Amono.set(i, Amono.get(i)
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "A")
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "a"));
                                    }
                                    if (buffer.substring(seekstart + 1, seekend + 1).contains("T")
                                            || buffer.substring(seekstart + 1, seekend + 1).contains("t")) {
                                        Tmono.set(i, Tmono.get(i)
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "T")
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "t"));
                                    }
                                    if (buffer.substring(seekstart + 1, seekend + 1).contains("G")
                                            || buffer.substring(seekstart + 1, seekend + 1).contains("g")) {
                                        Gmono.set(i, Gmono.get(i)
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "G")
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "g"));
                                    }
                                    if (buffer.substring(seekstart + 1, seekend + 1).contains("C")
                                            || buffer.substring(seekstart + 1, seekend + 1).contains("c")) {
                                        Cmono.set(i, Cmono.get(i)
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "C")
                                                + StringUtils.countMatches(
                                                        buffer.substring(seekstart + 1, seekend + 1), "c"));
                                    }
                                    outmono.writeInt(real_start + 1);
                                    outmono.writeInt(real_end + 1);
                                } else if (ssrs.get(1).length() == 2) {
                                    countdi.set(i, countdi.get(i) + 1);
                                    countdire.set(i, countdire.get(i) + real_end - real_start);

                                    if (buffer.substring(seekstart, seekend).contains("A")
                                            || buffer.substring(seekstart, seekend).contains("a")) {
                                        Adi.set(i,
                                                Adi.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "A")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "a"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("T")
                                            || buffer.substring(seekstart, seekend).contains("t")) {
                                        Tdi.set(i,
                                                Tdi.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "T")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "t"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("G")
                                            || buffer.substring(seekstart, seekend).contains("g")) {
                                        Gdi.set(i,
                                                Gdi.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "G")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "g"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("C")
                                            || buffer.substring(seekstart, seekend).contains("c")) {
                                        Cdi.set(i,
                                                Cdi.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "C")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "c"));
                                    }

                                    outdi.writeUTF(buffer.substring(seekstart, seekend));
                                    outdi.writeInt(real_start);
                                    outdi.writeInt(real_end);

                                } else if (ssrs.get(1).length() == 3) {

                                    counttri.set(i, counttri.get(i) + 1);
                                    counttrire.set(i, counttrire.get(i) + real_end - real_start);

                                    if (buffer.substring(seekstart, seekend).contains("A")
                                            || buffer.substring(seekstart, seekend).contains("a")) {
                                        Atri.set(i,
                                                Atri.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "A")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "a"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("T")
                                            || buffer.substring(seekstart, seekend).contains("t")) {
                                        Ttri.set(i,
                                                Ttri.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "T")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "t"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("G")
                                            || buffer.substring(seekstart, seekend).contains("g")) {
                                        Gtri.set(i,
                                                Gtri.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "G")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "g"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("C")
                                            || buffer.substring(seekstart, seekend).contains("c")) {
                                        Ctri.set(i,
                                                Ctri.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "C")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "c"));
                                    }

                                    outtri.writeUTF(buffer.substring(seekstart, seekend));
                                    outtri.writeInt(real_start);
                                    outtri.writeInt(real_end);

                                } else if (ssrs.get(1).length() == 4) {

                                    counttetra.set(i, counttetra.get(i) + 1);
                                    counttetrare.set(i, counttetrare.get(i) + real_end - real_start);

                                    if (buffer.substring(seekstart, seekend).contains("A")
                                            || buffer.substring(seekstart, seekend).contains("a")) {
                                        Atetra.set(i,
                                                Atetra.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "A")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "a"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("T")
                                            || buffer.substring(seekstart, seekend).contains("t")) {
                                        Ttetra.set(i,
                                                Ttetra.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "T")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "t"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("G")
                                            || buffer.substring(seekstart, seekend).contains("g")) {
                                        Gtetra.set(i,
                                                Gtetra.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "G")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "g"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("C")
                                            || buffer.substring(seekstart, seekend).contains("c")) {
                                        Ctetra.set(i,
                                                Ctetra.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "C")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "c"));
                                    }
                                    outtetra.writeUTF(buffer.substring(seekstart, seekend));
                                    outtetra.writeInt(real_start);
                                    outtetra.writeInt(real_end);

                                } else if (ssrs.get(1).length() == 5) {
                                    countpenta.set(i, countpenta.get(i) + 1);
                                    countpentare.set(i, countpentare.get(i) + real_end - real_start);

                                    if (buffer.substring(seekstart, seekend).contains("A")
                                            || buffer.substring(seekstart, seekend).contains("a")) {
                                        Apenta.set(i,
                                                Apenta.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "A")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "a"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("T")
                                            || buffer.substring(seekstart, seekend).contains("t")) {
                                        Tpenta.set(i,
                                                Tpenta.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "T")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "t"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("G")
                                            || buffer.substring(seekstart, seekend).contains("g")) {
                                        Gpenta.set(i,
                                                Gpenta.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "G")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "g"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("C")
                                            || buffer.substring(seekstart, seekend).contains("c")) {
                                        Cpenta.set(i,
                                                Cpenta.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "C")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "c"));
                                    }

                                    outpenta.writeUTF(buffer.substring(seekstart, seekend));
                                    outpenta.writeInt(real_start);
                                    outpenta.writeInt(real_end);

                                } else if (ssrs.get(1).length() == 6) {
                                    counthexa.set(i, counthexa.get(i) + 1);
                                    counthexare.set(i, counthexare.get(i) + real_end - real_start);

                                    if (buffer.substring(seekstart, seekend).contains("A")
                                            || buffer.substring(seekstart, seekend).contains("a")) {
                                        Ahexa.set(i,
                                                Ahexa.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "A")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "a"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("T")
                                            || buffer.substring(seekstart, seekend).contains("t")) {
                                        Thexa.set(i,
                                                Thexa.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "T")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "t"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("G")
                                            || buffer.substring(seekstart, seekend).contains("g")) {
                                        Ghexa.set(i,
                                                Ghexa.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "G")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "g"));
                                    }
                                    if (buffer.substring(seekstart, seekend).contains("C")
                                            || buffer.substring(seekstart, seekend).contains("c")) {
                                        Chexa.set(i,
                                                Chexa.get(i)
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "C")
                                                        + StringUtils.countMatches(
                                                                buffer.substring(seekstart, seekend), "c"));
                                    }

                                    outhexa.writeUTF(buffer.substring(seekstart, seekend));
                                    outhexa.writeInt(real_start);
                                    outhexa.writeInt(real_end);

                                }
                                //out.println("SSR: " + buffer.substring(seekstart, seekend) + " start-end: " + real_start + "-" + real_end);
                                stdin.close();

                            }
                        }

                    } catch (EOFException e) {
                        eof = true;
                    }
                }
                in.close();
                outmono.close();
                outdi.close();
                outtri.close();
                outtetra.close();
                outpenta.close();
                outhexa.close();

                DataOutputStream save = new DataOutputStream(new BufferedOutputStream(
                        new FileOutputStream(files.substring(0, files.lastIndexOf('/')) + "/imperf_stats")));
                save.writeInt(countmono.get(i));
                save.writeInt(countdi.get(i));
                save.writeInt(counttri.get(i));
                save.writeInt(counttetra.get(i));
                save.writeInt(countpenta.get(i));
                save.writeInt(counthexa.get(i));
                save.writeInt(countmonore.get(i));
                save.writeInt(countdire.get(i));
                save.writeInt(counttrire.get(i));
                save.writeInt(counttetrare.get(i));
                save.writeInt(countpentare.get(i));
                save.writeInt(counthexare.get(i));
                save.writeInt(Amono.get(i));
                save.writeInt(Tmono.get(i));
                save.writeInt(Gmono.get(i));
                save.writeInt(Cmono.get(i));
                save.writeInt(Adi.get(i));
                save.writeInt(Tdi.get(i));
                save.writeInt(Gdi.get(i));
                save.writeInt(Cdi.get(i));
                save.writeInt(Atri.get(i));
                save.writeInt(Ttri.get(i));
                save.writeInt(Gtri.get(i));
                save.writeInt(Ctri.get(i));
                save.writeInt(Atetra.get(i));
                save.writeInt(Ttetra.get(i));
                save.writeInt(Gtetra.get(i));
                save.writeInt(Ctetra.get(i));
                save.writeInt(Apenta.get(i));
                save.writeInt(Tpenta.get(i));
                save.writeInt(Gpenta.get(i));
                save.writeInt(Cpenta.get(i));
                save.writeInt(Ahexa.get(i));
                save.writeInt(Thexa.get(i));
                save.writeInt(Ghexa.get(i));
                save.writeInt(Chexa.get(i));
                save.close();

            } else {
                DataInputStream save = new DataInputStream(new BufferedInputStream(
                        new FileInputStream(files.substring(0, files.lastIndexOf('/')) + "/imperf_stats")));

                countmono.set(i, save.readInt());
                countdi.set(i, save.readInt());
                counttri.set(i, save.readInt());
                counttetra.set(i, save.readInt());
                countpenta.set(i, save.readInt());
                counthexa.set(i, save.readInt());
                countmonore.set(i, save.readInt());
                countdire.set(i, save.readInt());
                counttrire.set(i, save.readInt());
                counttetrare.set(i, save.readInt());
                countpentare.set(i, save.readInt());
                counthexare.set(i, save.readInt());
                Amono.set(i, save.readInt());
                Tmono.set(i, save.readInt());
                Gmono.set(i, save.readInt());
                Cmono.set(i, save.readInt());
                Adi.set(i, save.readInt());
                Tdi.set(i, save.readInt());
                Gdi.set(i, save.readInt());
                Cdi.set(i, save.readInt());
                Atri.set(i, save.readInt());
                Ttri.set(i, save.readInt());
                Gtri.set(i, save.readInt());
                Ctri.set(i, save.readInt());
                Atetra.set(i, save.readInt());
                Ttetra.set(i, save.readInt());
                Gtetra.set(i, save.readInt());
                Ctetra.set(i, save.readInt());
                Apenta.set(i, save.readInt());
                Tpenta.set(i, save.readInt());
                Gpenta.set(i, save.readInt());
                Cpenta.set(i, save.readInt());
                Ahexa.set(i, save.readInt());
                Thexa.set(i, save.readInt());
                Ghexa.set(i, save.readInt());
                Chexa.set(i, save.readInt());
                save.close();
            }
        }

    }

}

From source file:com.codename1.impl.android.AndroidImplementation.java

/**
 * Gets the service properties.  Will read properties from file so that
 * they are available even if CN1 is not initialized.
 * @param a/*from  w  w  w  . j  av a  2s .  c  o  m*/
 * @return 
 */
public static Map<String, String> getServiceProperties(Context a) {
    if (serviceProperties == null) {
        InputStream i = null;
        try {
            serviceProperties = new HashMap<String, String>();
            i = a.openFileInput("CN1$AndroidServiceProperties");
            if (i == null) {
                return serviceProperties;
            }
            DataInputStream is = new DataInputStream(i);
            int count = is.readInt();
            for (int idx = 0; idx < count; idx++) {
                String key = is.readUTF();
                String value = is.readUTF();
                serviceProperties.put(key, value);
            }
        } catch (IOException ex) {
            Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if (i != null)
                    i.close();
            } catch (Throwable ex) {
                Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    return serviceProperties;
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public static void firePendingPushes(final PushCallback c, final Context a) {
    try {//from  w  ww.j  a v  a 2 s .  c  o  m
        if (c != null) {
            InputStream i = a.openFileInput("CN1$AndroidPendingNotifications");
            if (i == null) {
                return;
            }
            DataInputStream is = new DataInputStream(i);
            int count = is.readByte();
            for (int iter = 0; iter < count; iter++) {
                boolean hasType = is.readBoolean();
                String actualType = null;
                if (hasType) {
                    actualType = is.readUTF();
                }
                final String t;
                final String b;
                final String category;
                final String image;
                if ("99".equals(actualType)) {
                    // This was a rich push
                    Map<String, String> vals = splitQuery(is.readUTF());
                    t = vals.get("type");
                    b = vals.get("body");
                    category = vals.get("category");
                    image = vals.get("image");
                } else {
                    t = actualType;
                    b = is.readUTF();
                    category = null;
                    image = null;
                }
                long s = is.readLong();
                Display.getInstance().callSerially(new Runnable() {
                    @Override
                    public void run() {
                        Display.getInstance().setProperty("pendingPush", "true");
                        Display.getInstance().setProperty("pushType", t);
                        initPushContent(b, image, t, category, a);
                        if (t != null && ("3".equals(t) || "6".equals(t))) {
                            String[] a = b.split(";");
                            c.push(a[0]);
                            c.push(a[1]);
                        } else if (t != null && ("101".equals(t))) {
                            c.push(b.substring(b.indexOf(" ") + 1));
                        } else {
                            c.push(b);
                        }
                        Display.getInstance().setProperty("pendingPush", null);
                    }
                });
            }
            a.deleteFile("CN1$AndroidPendingNotifications");
        }
    } catch (IOException err) {
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public static String[] getPendingPush(String type, Context a) {
    InputStream i = null;//w w  w .  ja  v  a2  s .c  o m
    try {
        i = a.openFileInput("CN1$AndroidPendingNotifications");
        if (i == null) {
            return null;
        }
        DataInputStream is = new DataInputStream(i);
        int count = is.readByte();
        Vector v = new Vector<String>();
        for (int iter = 0; iter < count; iter++) {
            boolean hasType = is.readBoolean();
            String actualType = null;
            if (hasType) {
                actualType = is.readUTF();
            }

            final String t;
            final String b;
            if ("99".equals(actualType)) {
                // This was a rich push
                Map<String, String> vals = splitQuery(is.readUTF());
                t = vals.get("type");
                b = vals.get("body");
                //category = vals.get("category");
                //image = vals.get("image");
            } else {
                t = actualType;
                b = is.readUTF();
                //category = null;
                //image = null;
            }
            long s = is.readLong();
            if (t != null && ("3".equals(t) || "6".equals(t))) {
                String[] m = b.split(";");
                v.add(m[0]);
            } else if (t != null && "4".equals(t)) {
                String[] m = b.split(";");
                v.add(m[1]);
            } else if (t != null && "2".equals(t)) {
                continue;
            } else if (t != null && "101".equals(t)) {
                v.add(b.substring(b.indexOf(" ") + 1));
            } else {
                v.add(b);
            }
        }
        String[] retVal = new String[v.size()];
        for (int j = 0; j < retVal.length; j++) {
            retVal[j] = (String) v.get(j);
        }
        return retVal;

    } catch (Exception ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (i != null) {
                i.close();
            }
        } catch (IOException ex) {
        }
    }
    return null;
}