Example usage for java.io DataOutputStream writeUTF

List of usage examples for java.io DataOutputStream writeUTF

Introduction

In this page you can find the example usage for java.io DataOutputStream writeUTF.

Prototype

public final void writeUTF(String str) throws IOException 

Source Link

Document

Writes a string to the underlying output stream using modified UTF-8 encoding in a machine-independent manner.

Usage

From source file:carnero.cgeo.original.libs.Base.java

public boolean runExternalMap(int application, Activity activity, Resources res, Warning warning,
        GoogleAnalyticsTracker tracker, Cache cache, Waypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }//from  ww  w .  j a  va2 s  . c o  m

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<Waypoint> waypoints = new ArrayList<Waypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (Waypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (Waypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(Settings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}

From source file:carnero.cgeo.cgBase.java

public boolean runExternalMap(int application, Activity activity, Resources res, cgWarning warning,
        GoogleAnalyticsTracker tracker, cgCache cache, cgWaypoint waypoint, Double latitude, Double longitude) {
    if (cache == null && waypoint == null && latitude == null && longitude == null) {
        return false;
    }/*w  w w. java 2  s.  c o  m*/

    if (application == mapAppLocus) {
        // locus
        try {
            final Intent intentTest = new Intent(Intent.ACTION_VIEW);
            intentTest.setData(Uri.parse("menion.points:x"));

            if (isIntentAvailable(activity, intentTest) == true) {
                final ArrayList<cgWaypoint> waypoints = new ArrayList<cgWaypoint>();
                // get only waypoints with coordinates
                if (cache != null && cache.waypoints != null && cache.waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : cache.waypoints) {
                        if (wp.latitude != null && wp.longitude != null) {
                            waypoints.add(wp);
                        }
                    }
                }

                final ByteArrayOutputStream baos = new ByteArrayOutputStream();
                final DataOutputStream dos = new DataOutputStream(baos);

                dos.writeInt(1); // not used
                if (cache != null) {
                    if (waypoints == null || waypoints.isEmpty() == true) {
                        dos.writeInt(1); // cache only
                    } else {
                        dos.writeInt((1 + waypoints.size())); // cache and waypoints
                    }
                } else {
                    dos.writeInt(1); // one waypoint
                }

                int icon = -1;
                if (cache != null) {
                    icon = getIcon(true, cache.type, cache.own, cache.found, cache.disabled || cache.archived);
                } else if (waypoint != null) {
                    icon = getIcon(false, waypoint.type, false, false, false);
                } else {
                    icon = getIcon(false, "waypoint", false, false, false);
                }

                if (icon > 0) {
                    // load icon
                    Bitmap bitmap = BitmapFactory.decodeResource(res, icon);
                    ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                    bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                    byte[] image = baos2.toByteArray();

                    dos.writeInt(image.length);
                    dos.write(image);
                } else {
                    // no icon
                    dos.writeInt(0); // no image
                }

                // name
                if (cache != null && cache.name != null && cache.name.length() > 0) {
                    dos.writeUTF(cache.name);
                } else if (waypoint != null && waypoint.name != null && waypoint.name.length() > 0) {
                    dos.writeUTF(waypoint.name);
                } else {
                    dos.writeUTF("");
                }

                // description
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF(cache.geocode.toUpperCase());
                } else if (waypoint != null && waypoint.lookup != null && waypoint.lookup.length() > 0) {
                    dos.writeUTF(waypoint.lookup.toUpperCase());
                } else {
                    dos.writeUTF("");
                }

                // additional data :: keyword, button title, package, activity, data name, data content
                if (cache != null && cache.geocode != null && cache.geocode.length() > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeodetail;geocode;" + cache.geocode);
                } else if (waypoint != null && waypoint.id != null && waypoint.id > 0) {
                    dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + waypoint.id);
                } else {
                    dos.writeUTF("");
                }

                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    dos.writeDouble(cache.latitude); // latitude
                    dos.writeDouble(cache.longitude); // longitude
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    dos.writeDouble(waypoint.latitude); // latitude
                    dos.writeDouble(waypoint.longitude); // longitude
                } else {
                    dos.writeDouble(latitude); // latitude
                    dos.writeDouble(longitude); // longitude
                }

                // cache waypoints
                if (waypoints != null && waypoints.isEmpty() == false) {
                    for (cgWaypoint wp : waypoints) {
                        if (wp == null || wp.latitude == null || wp.longitude == null) {
                            continue;
                        }

                        final int wpIcon = getIcon(false, wp.type, false, false, false);

                        if (wpIcon > 0) {
                            // load icon
                            Bitmap bitmap = BitmapFactory.decodeResource(res, wpIcon);
                            ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                            bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos2);
                            byte[] image = baos2.toByteArray();

                            dos.writeInt(image.length);
                            dos.write(image);
                        } else {
                            // no icon
                            dos.writeInt(0); // no image
                        }

                        // name
                        if (wp.lookup != null && wp.lookup.length() > 0) {
                            dos.writeUTF(wp.lookup.toUpperCase());
                        } else {
                            dos.writeUTF("");
                        }

                        // description
                        if (wp.name != null && wp.name.length() > 0) {
                            dos.writeUTF(wp.name);
                        } else {
                            dos.writeUTF("");
                        }

                        // additional data :: keyword, button title, package, activity, data name, data content
                        if (wp.id != null && wp.id > 0) {
                            dos.writeUTF("intent;c:geo;carnero.cgeo;carnero.cgeo.cgeowaypoint;id;" + wp.id);
                        } else {
                            dos.writeUTF("");
                        }

                        dos.writeDouble(wp.latitude); // latitude
                        dos.writeDouble(wp.longitude); // longitude
                    }
                }

                final Intent intent = new Intent();
                intent.setAction(Intent.ACTION_VIEW);
                intent.setData(Uri.parse("menion.points:data"));
                intent.putExtra("data", baos.toByteArray());

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/locus");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppRmaps) {
        // rmaps
        try {
            final Intent intent = new Intent("com.robert.maps.action.SHOW_POINTS");

            if (isIntentAvailable(activity, intent) == true) {
                final ArrayList<String> locations = new ArrayList<String>();
                if (cache != null && cache.latitude != null && cache.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", cache.latitude) + ","
                            + String.format((Locale) null, "%.6f", cache.longitude) + ";" + cache.geocode + ";"
                            + cache.name);
                } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                    locations.add(String.format((Locale) null, "%.6f", waypoint.latitude) + ","
                            + String.format((Locale) null, "%.6f", waypoint.longitude) + ";" + waypoint.lookup
                            + ";" + waypoint.name);
                }

                intent.putStringArrayListExtra("locations", locations);

                activity.startActivity(intent);

                sendAnal(activity, tracker, "/external/rmaps");

                return true;
            }
        } catch (Exception e) {
            // nothing
        }
    }

    if (application == mapAppAny) {
        // fallback
        try {
            if (cache != null && cache.latitude != null && cache.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + cache.latitude + "," + cache.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            } else if (waypoint != null && waypoint.latitude != null && waypoint.longitude != null) {
                activity.startActivity(new Intent(Intent.ACTION_VIEW,
                        Uri.parse("geo:" + waypoint.latitude + "," + waypoint.longitude)));
                // INFO: q parameter works with Google Maps, but breaks cooperation with all other apps
            }

            sendAnal(activity, tracker, "/external/native/maps");

            return true;
        } catch (Exception e) {
            // nothing
        }
    }

    Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available.");

    if (warning != null && res != null) {
        warning.showToast(res.getString(R.string.err_application_no));
    }

    return false;
}

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

public static void writeServiceProperties(Context a) {
    if (servicePropertiesDirty()) {
        Map<String, String> out = getServiceProperties(a);

        for (String key : servicePropertyKeys) {

            String val = Display.getInstance().getProperty(key, null);
            if (val != null) {
                out.put(key, val);
            }/* www .  jav a2 s. c  om*/
            if ("true".equals(Display.getInstance().getProperty(key + "#delete", null))) {
                out.remove(key);

            }
        }

        OutputStream os = null;
        try {
            os = a.openFileOutput("CN1$AndroidServiceProperties", 0);
            if (os == null) {
                System.out.println("Failed to save service properties null output stream");
                return;
            }
            DataOutputStream dos = new DataOutputStream(os);
            dos.writeInt(out.size());
            for (String key : out.keySet()) {
                dos.writeUTF(key);
                dos.writeUTF((String) out.get(key));
            }
            serviceProperties = null;
        } catch (FileNotFoundException ex) {
            System.out.println(
                    "Service properties file not found.  This is normal for the first run.   On subsequent runs, the file should exist.");
        } catch (IOException ex) {

            Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                if (os != null)
                    os.close();
            } catch (Throwable ex) {
                Logger.getLogger(AndroidImplementation.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
}

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 w w .  j av  a  2 s.  co 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:com.codename1.impl.android.AndroidImplementation.java

public static void appendNotification(String type, String body, String image, String category, Context a) {
    try {/* ww w.  jav  a2s .  co m*/
        String[] fileList = a.fileList();
        byte[] data = null;
        for (int iter = 0; iter < fileList.length; iter++) {
            if (fileList[iter].equals("CN1$AndroidPendingNotifications")) {
                InputStream is = a.openFileInput("CN1$AndroidPendingNotifications");
                if (is != null) {
                    data = readInputStream(is);
                    sCleanup(a);
                    break;
                }
            }
        }
        DataOutputStream os = new DataOutputStream(a.openFileOutput("CN1$AndroidPendingNotifications", 0));
        if (data != null) {
            data[0]++;
            os.write(data);
        } else {
            os.writeByte(1);
        }
        String bodyType = type;
        if (image != null || category != null) {
            type = "99";
        }
        if (type != null) {
            os.writeBoolean(true);
            os.writeUTF(type);
        } else {
            os.writeBoolean(false);
        }
        if ("99".equals(type)) {
            String msg = "body=" + java.net.URLEncoder.encode(body, "UTF-8") + "&type="
                    + java.net.URLEncoder.encode(bodyType, "UTF-8");
            if (category != null) {
                msg += "&category=" + java.net.URLEncoder.encode(category, "UTF-8");
            }
            if (image != null) {
                image += "&image=" + java.net.URLEncoder.encode(image, "UTF-8");
            }
            os.writeUTF(msg);

        } else {
            os.writeUTF(body);
        }
        os.writeLong(System.currentTimeMillis());
    } catch (IOException err) {
        err.printStackTrace();
    }
}

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 w  w w  .j  a va2 s. 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();
            }
        }

    }

}