Example usage for java.lang NumberFormatException printStackTrace

List of usage examples for java.lang NumberFormatException printStackTrace

Introduction

In this page you can find the example usage for java.lang NumberFormatException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:massbank.BatchJobWorker.java

/**
 * Ytt@C???iHTML`?j/*from  w w w .j a  va  2s.c  om*/
 * @param time NGXg 
 * @param resultFile t@C
 * @param htmlFile YtpHTMLt@C
 */
private void createHtmlFile(String time, File resultFile, File htmlFile) {
    NumberFormat nf = NumberFormat.getNumberInstance();
    LineNumberReader in = null;
    PrintWriter out = null;
    try {
        in = new LineNumberReader(new FileReader(resultFile));
        out = new PrintWriter(new BufferedWriter(new FileWriter(htmlFile)));

        // wb_?[?o
        String reqIonStr = "Both";
        try {
            if (Integer.parseInt(this.ion) > 0) {
                reqIonStr = "Positive";
            } else if (Integer.parseInt(this.ion) < 0) {
                reqIonStr = "Negative";
            }
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
        out.println("<html>");
        out.println("<head><title>MassBank Batch Service Results</title></head>");
        out.println("<body>");
        out.println(
                "<h1><a href=\"http://www.massbank.jp/\" target=\"_blank\">MassBank</a> Batch Service Results</h1>");
        out.println("<hr>");
        out.println("<h2>Request Date : " + time + "<h2>");
        out.println("Instrument Type : " + this.inst + "<br>");
        out.println("Ion Mode : " + reqIonStr + "<br>");
        out.println("<br><hr>");

        // ?o
        String line;
        long queryCnt = 0;
        boolean readName = false;
        boolean readHit = false;
        boolean readNum = false;
        while ((line = in.readLine()) != null) {
            if (in.getLineNumber() < 4) {
                continue;
            }
            if (!readName) {
                queryCnt++;
                out.println("<h2>Query " + nf.format(queryCnt) + "</h2><br>");
                out.println("Name: " + line.trim() + "<br>");
                readName = true;
            } else if (!readHit) {
                out.println("Hit: " + nf.format(Integer.parseInt(line.trim())) + "<br>");
                readHit = true;
            } else if (!readNum) {
                out.println("<table border=\"1\">");
                out.println("<tr><td colspan=\"6\">Top " + line.trim() + " List</td></tr>");
                out.println(
                        "<tr><th>Accession</th><th>Title</th><th>Formula</th><th>Ion</th><th>Score</th><th>Hit</th></tr>");
                readNum = true;
            } else {
                if (!line.trim().equals("")) {
                    String[] data = formatLine(line);
                    String acc = data[0];
                    String title = data[1];
                    String formula = data[2];
                    String ion = data[3];
                    String score = data[4];
                    String hit = data[5];

                    out.println("<tr>");
                    out.println("<td><a href=\"http://www.massbank.jp/jsp/FwdRecord.jsp?id=" + acc
                            + "\" target=\"_blank\">" + acc + "</td>");
                    out.println("<td>" + title + "</td>");
                    out.println("<td>" + formula + "</td>");
                    out.println("<td>" + ion + "</td>");
                    out.println("<td>" + score + "</td>");
                    out.println("<td align=\"right\">" + hit + "</td>");
                    out.println("</tr>");
                } else {
                    out.println("</table>");
                    out.println("<hr>");
                    readName = false;
                    readHit = false;
                    readNum = false;
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
        }
        if (out != null) {
            out.flush();
            out.close();
        }
    }
}

From source file:org.camera.service.FastaValidation.java

/** Output the data read from the file or URL as a string.
 *  @exception IllegalActionException If there is no director or
 *   if reading the file triggers an exception.
 *///  w w  w.  j av  a 2  s  .  c  om
public void fire() throws IllegalActionException {
    super.fire();
    parseNumSequence.update();

    boolean monitor = true;
    boolean parseAllSequences = true;

    String filePath = null;
    StringBuilder message = new StringBuilder();

    // If the fileOrURL input port is connected and has data, then
    // get the file name from there.

    String numOfSeqBeParsedValue = getPortParamValue();
    int numOfSeqBeParsed = -1;
    if (!ServiceUtils.checkEmptyString(numOfSeqBeParsedValue)) {

        try {
            numOfSeqBeParsed = Integer.parseInt(numOfSeqBeParsedValue);
            if (numOfSeqBeParsed > 0) {
                parseAllSequences = false;
            }
        } catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }

    }

    if (inputPortFilePath.isOutsideConnected()) {
        if (inputPortFilePath.hasToken(0)) {
            String name = ((StringToken) inputPortFilePath.get(0)).stringValue();

            // Using setExpression() rather than setToken() allows
            // the string to refer to variables defined in the
            // scope of this actor.
            fileParameter.setExpression(name);

        }
    }
    filePath = fileParameter.getExpression();

    if (ServiceUtils.checkEmptyString(filePath)) {
        message.append("NO FILE NAME PROVIDED");
        outputPortStatus.send(0, new BooleanToken(monitor));
        outputPortMessage.send(0, new StringToken(String.valueOf(message.toString())));

        log.debug("FILE PATH IS EMPTY");
        message = null;
        return;
    }

    log.debug("FILE NAME: " + filePath);

    String type = null;
    if (inputPortType.isOutsideConnected()) {
        if (inputPortType.hasToken(0)) {
            type = ((StringToken) inputPortType.get(0)).stringValue();
            if (type.equalsIgnoreCase(PROTEIN)) {
                dropDownValue.setExpression(PROTEIN);
            } else if (type.equalsIgnoreCase(DNA)) {
                dropDownValue.setExpression(DNA);
            } else if (type.equalsIgnoreCase(RNA)) {
                dropDownValue.setExpression(RNA);
            }
        }
    }

    if (ServiceUtils.checkEmptyString(dropDownValue.getExpression())) {
        dropDownValue.setExpression(DNA);
        message.append("NO SELECTION MADE FOR TYPE: DEFAULT VALUE IS SET TO DNA");
    } else {
        message.append("SELECTION MADE BY USER FOR TYPE: ").append(dropDownValue.getExpression());
    }
    message.append(ServiceUtils.LINESEP);

    type = dropDownValue.getExpression();

    log.debug("SELECTED VALUE FROM DROP DOWN: " + type);

    BufferedReader br = null;
    try {
        br = new BufferedReader(new FileReader(filePath));
    } catch (FileNotFoundException ex) {
        //problem reading file
        System.out.println("FILE NOT FOUND");
        ex.printStackTrace();
        System.exit(1);
    }

    Namespace nm = new SimpleNamespace("CAMERA");
    //get a SequenceDB of all sequences in the file
    RichSequenceIterator db = null;
    if (type.equals(DNA)) {
        db = RichSequence.IOTools.readFastaDNA(br, nm); //readFasta(is, alpha);
    } else if (type.equals(RNA)) {
        db = RichSequence.IOTools.readFastaRNA(br, nm); //readFasta(is, alpha);
    } else if (type.equals(PROTEIN)) {
        db = RichSequence.IOTools.readFastaProtein(br, nm); //readFasta(is, alpha);
    }

    int number_of_sequences = 0;

    int icheck = 0;
    int problems = 0;
    List<String> allM = new ArrayList<String>();
    RichSequence rseq = null;
    boolean fileStatus = true;

    /**
     * Here, I am attempting to read first sequence to check file status
     * before proceeding forward. I have to do this because of
     * clunky behavior or biojava.
     */
    if (db.hasNext()) {
        try {
            rseq = db.nextRichSequence();
            number_of_sequences++;
        } catch (BioException bioexcep) {
            fileStatus = false;
            System.out.println("FILE STATUS: " + fileStatus);
            message.append("INCORRECT FILE FORMAT OR FILE EMPTY OR FIRST SEQ HAS PROBLEM");
            monitor = false;
        }
    }

    while (db.hasNext() && fileStatus) {
        number_of_sequences++;
        try {
            //              Sequence seq = db.nextSequence();
            rseq = db.nextRichSequence();
            //              log.debug("ACCESSION: " + rseq.getAccession()); //NAME, URN, & ACCESSION COULD BE VERY SIMILAR
            //              log.debug("SEQUENCE-NAME: " + rseq.getURN());
            //              log.debug("SEQUENCE-ENGTH: " + rseq.length());
            //              log.debug("SEQUENCE: " + rseq.seqString());

            /*                       
                          Annotation seqAn = rseq.getAnnotation();
                          for (Iterator i = seqAn.keys().iterator(); i.hasNext(); ) {
                             Object key = i.next();
                             Object value = seqAn.getProperty(key);
                             log.debug(key.toString() + ": " + value.toString());
                          }
            */

            //user controls how many sequences need o be parsed.
            if (!parseAllSequences && number_of_sequences >= numOfSeqBeParsed) {
                break;
            }

        } catch (ParseException parex) {
            monitor = false;
            message.append("INCORRECT FILE FORMAT OR FILE NOT PARSEABLE OR PROBLEM WITH SEQUENCES")
                    .append(ServiceUtils.LINESEP);
            message.append("PROBLEM WITH SEQUENCE #: " + (number_of_sequences + 1));
            //               .append(ex.getMessage());
            //not in fasta format or wrong alphabet
            parex.printStackTrace();

        } catch (BioException ex) {
            //               message.append(ex.getMessage() + "\n");
            monitor = false;
            //               message.append("HI");
            //no fasta sequences in the file
            ex.printStackTrace();

            StringWriter writer = new StringWriter();
            ex.printStackTrace(new PrintWriter(writer));
            String trace = writer.toString();

            // The following line may give impression that the catching
            // IOException should obviate the need for if block. But do
            // not waste time trying because it does not work. The
            // version 1.7.1 of Biojava currently available now is quirky.
            if (trace.contains("IOException")) {
                ++icheck;
                if (icheck % 2 == 0) {
                    ++problems;
                    allM.add("Problem at sequence :: " + --number_of_sequences);
                }
            } else {
                ++problems;
                allM.add("Problem at sequence : " + number_of_sequences);
            }
            if (problems > MAXNOOFALLOWEDPROBLEMS) {
                message.append("Number of problems exceeded :" + MAXNOOFALLOWEDPROBLEMS);
                break;
            }

        } catch (Throwable throwable) {
            monitor = false;
            message.append("IN THROWABLE\n");
            throwable.printStackTrace();
        } finally {
            if (fileParameter != null) {
                fileParameter.close();
            }
        } //end try block

    } //end while

    if (allM.size() > 0) {
        for (String m : allM) {
            message.append(m + "\n");
        }
    }

    message.append("Number of sequences parsed from the file: ").append(String.valueOf(number_of_sequences))
            .append(ServiceUtils.LINESEP);

    outputPortMessage.send(0, new StringToken(String.valueOf(message.toString())));
    outputPortStatus.send(0, new BooleanToken(monitor));

    log.debug("MESSAGE: " + message.toString());
    message = null;

}

From source file:de.madvertise.android.sdk.MadvertiseAd.java

/**
 * Constructor, blocking due to http request, should be called in a thread
 * pool, a request queue, a network thread
 *
 * @param context the applications context
 * @param json json object containing all ad information
 *///from   w  ww. j  a  v  a  2 s.c  om
protected MadvertiseAd(final Context context, final JSONObject json,
        final MadvertiseViewCallbackListener listener) {
    this.mContext = context;
    this.mCallbackListener = listener;

    MadvertiseUtil.logMessage(null, Log.DEBUG, "Creating ad");

    // init json arrays and print all keys / values
    mJsonNames = json.names();
    try {
        mJsonValues = json.toJSONArray(mJsonNames);

        for (int i = 0; i < mJsonNames.length(); i++) {
            MadvertiseUtil.logMessage(null, Log.DEBUG,
                    "Key => " + mJsonNames.getString(i) + " Value => " + mJsonValues.getString(i));
        }

        markup = MadvertiseUtil.getJSONValue(json, MARKUP);
        if (null != markup && !markup.equals("")) {
            mBannerType = MadvertiseUtil.BANNER_TYPE_RICH_MEDIA;
            mIsMraid = true;
            mHasBanner = true;
            mBannerHeight = Integer.parseInt(MadvertiseUtil.getJSONValue(json, "height"));
            mBannerWidth = Integer.parseInt(MadvertiseUtil.getJSONValue(json, "width"));
            return;
        }

        // first get not nested values
        mClickUrl = MadvertiseUtil.getJSONValue(json, CLICK_URL_CODE);
        mText = MadvertiseUtil.getJSONValue(json, TEXT_CODE);
        mImpressionTrackingArray = MadvertiseUtil.getJSONArray(json, IMPRESSION_TRACKING_ARRAY_CODE);

        // check, if we have a banner
        JSONObject bannerJson = MadvertiseUtil.getJSONObject(json, "banner");
        if (bannerJson == null) {
            return;
        }

        // logic for new ad response
        mBannerUrl = MadvertiseUtil.getJSONValue(bannerJson, BANNER_URL_CODE);
        mHasBanner = true;
        mBannerType = MadvertiseUtil.getJSONValue(bannerJson, "type");

        // check, if rich media banner
        JSONObject richMediaJson = MadvertiseUtil.getJSONObject(bannerJson, "rich_media");
        if (richMediaJson == null) {
            return;
        }

        // check, if mraid type
        if (!MadvertiseUtil.getJSONBoolean(richMediaJson, "mraid")) {
            mHasBanner = false;
            mBannerUrl = "";
            return;
        }

        mIsMraid = true;

        // overwrite banner url
        mBannerUrl = MadvertiseUtil.getJSONValue(richMediaJson, "full_url");

        // get sizes for rich media ad
        try {
            mBannerHeight = Integer.parseInt(MadvertiseUtil.getJSONValue(richMediaJson, "height"));
            mBannerWidth = Integer.parseInt(MadvertiseUtil.getJSONValue(richMediaJson, "width"));
        } catch (NumberFormatException e) {
            mBannerHeight = 53;
            mBannerWidth = 320;
        }

    } catch (JSONException e) {
        MadvertiseUtil.logMessage(null, Log.DEBUG, "Error in json string");
        if (mCallbackListener != null) {
            mCallbackListener.onError(e);
        }
        e.printStackTrace();
    }
}

From source file:ca.mudar.parkcatcher.ui.activities.MainActivity.java

private void updateParkingTimeFromUri(Uri uri) {
    Log.v(TAG, "updateParkingTimeFromUri");
    List<String> pathSegments = uri.getPathSegments();

    // http://www.capteurdestationnement.com/map/search/2/15.5/12
    // http://www.capteurdestationnement.com/map/search/2/15.5/12/h2w2e7

    if ((pathSegments.size() >= 5) && (pathSegments.get(0).equals(Const.INTENT_EXTRA_URL_PATH_MAP))
            && (pathSegments.get(1).equals(Const.INTENT_EXTRA_URL_PATH_SEARCH))) {

        try {/*from   ww w . j a v a 2 s.com*/
            final int day = Integer.valueOf(pathSegments.get(2));
            final double time = Double.valueOf(pathSegments.get(3));
            final int duration = Integer.valueOf(pathSegments.get(4));

            final int hourOfDay = (int) time;
            final int minute = (int) ((time - hourOfDay) * 60);

            GregorianCalendar calendar = new GregorianCalendar();

            calendar.set(Calendar.DAY_OF_WEEK, day == 7 ? Calendar.SUNDAY : day + 1);
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);

            parkingApp.setParkingCalendar(calendar);
            parkingApp.setParkingDuration(duration);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }
}

From source file:org.dklisiaris.downtown.helper.XMLParser.java

public ArrayList<Company> getAllCompanies(Document doc) {
    ArrayList<Company> companies = new ArrayList<Company>();

    //Document doc = getDomElement(xml); // getting DOM element
    NodeList nl = doc.getElementsByTagName(KEY_PRODUCT);

    // looping through all item nodes <category>
    for (int k = 0; k < nl.getLength(); k++) {
        Element e = (Element) nl.item(k);
        int co_id = Integer.parseInt(getValue(e, KEY_ID));
        int avail = getValue(e, KEY_AVAIL).equals("yes") ? 1 : 0;
        int level = Integer.parseInt(getValue(e, KEY_LEVEL));
        int cat_id = Integer.parseInt(getAttributeFromNode(e, KEY_CATEGORY, ATTR_CATEGORY_ID));
        String website = null;/*from  w w  w. jav a  2s. c om*/
        if (avail == 1)
            website = getValue(e, KEY_WEBSITE);
        double langi = 0.0, longi = 0.0;
        ArrayList<String> imgs = getImgUrlsFromElem(e, KEY_IMAGE);
        ArrayList<String> tels = getMultiValuesFromElem(e, KEY_TEL);
        ArrayList<String> subcats = new ArrayList<String>();
        NodeList subItems = e.getElementsByTagName(KEY_SUBCATEGORY);
        for (int j = 0; j < subItems.getLength(); j++) {
            Element subItem = (Element) subItems.item(j);
            subcats.add(subItem.getAttribute(ATTR_CATEGORY_ID));
        }
        String county = getValue(e, KEY_COUNTY);
        String tk = getValue(e, KEY_TK);
        String fax = getValue(e, KEY_FAX);
        String strLang = getValue(e, KEY_LANG), strLong = getValue(e, KEY_LONG);
        //Log.d("Coords: ",strLang+" - "+strLong);
        if (exists(strLang) && exists(strLong)) {
            try {
                langi = Double.parseDouble(getValue(e, KEY_LANG));
                longi = Double.parseDouble(getValue(e, KEY_LONG));
            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
        Company com = new Company(co_id, getValue(e, KEY_NAME), getValue(e, KEY_ADDRESS), getValue(e, KEY_DESC),
                imgs, tels, subcats, cat_id, getValue(e, KEY_AREA), county, tk, level, avail, website, fax,
                langi, longi);
        //Log.d("Namexml",pr.getName());
        companies.add(com);

    }
    return companies;

}

From source file:com.idega.company.business.impl.CompanyServiceImpl.java

protected ArrayList<User> getUsersByRoles(Collection<String> roles) {
    if (ListUtil.isEmpty(roles)) {
        getLogger().warning("Roles are not provided");
        return null;
    }/*from   ww  w . ja v a 2 s.com*/

    ArrayList<User> users = new ArrayList<User>();
    GroupBusiness groupBusiness = getGroupBusiness();
    if (groupBusiness == null) {
        return null;
    }

    UserBusiness userBusiness = getUserBusiness();
    if (userBusiness == null) {
        return null;
    }

    AccessController accessController = CoreUtil.getIWContext().getAccessController();
    for (String roleKey : roles) {
        Collection<Group> groupsByRole = accessController.getAllGroupsForRoleKey(roleKey,
                CoreUtil.getIWContext());
        if (ListUtil.isEmpty(groupsByRole)) {
            continue;
        }

        for (Group group : groupsByRole) {
            if (StringUtil.isEmpty(group.getName())) {
                try {
                    User user = userBusiness.getUser(Integer.valueOf(group.getId()));
                    if (accessController.hasRole(user, roleKey) && !users.contains(user)) {
                        users.add(user);
                    }
                } catch (NumberFormatException e) {
                    e.printStackTrace();
                } catch (Exception e) {
                }
            }

            Collection<User> usersInGroup = null;
            try {
                usersInGroup = groupBusiness.getUsers(group);
            } catch (FinderException e) {
            } catch (Exception e) {
                e.printStackTrace();
            }

            if (!ListUtil.isEmpty(usersInGroup)) {
                for (User user : usersInGroup) {
                    if (!users.contains(user)) {
                        users.add(user);
                    }
                }
            }
        }
    }

    if (ListUtil.isEmpty(users)) {
        getLogger().warning("There are no users by role(s): " + roles);
    }
    return users;
}

From source file:de.baumann.hhsmoodle.data_random.Random_Fragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_screen_dice, container, false);

    ImageView imgHeader = (ImageView) rootView.findViewById(R.id.imageView_header);
    helper_main.setImageHeader(getActivity(), imgHeader);

    fab_dice = (FloatingActionButton) rootView.findViewById(R.id.fab_dice);
    lv = (ListView) rootView.findViewById(R.id.list);
    viewPager = (ViewPager) getActivity().findViewById(R.id.viewpager);
    lvItems = (ListView) rootView.findViewById(R.id.lvItems);

    fabLayout1 = (LinearLayout) rootView.findViewById(R.id.fabLayout1);
    fabLayout2 = (LinearLayout) rootView.findViewById(R.id.fabLayout2);
    fab = (FloatingActionButton) rootView.findViewById(R.id.fab);
    FloatingActionButton fab1 = (FloatingActionButton) rootView.findViewById(R.id.fab1);
    FloatingActionButton fab2 = (FloatingActionButton) rootView.findViewById(R.id.fab2);

    fab.setOnClickListener(new View.OnClickListener() {
        @Override//www . j a  va2  s  . c o m
        public void onClick(View view) {
            if (!isFABOpen) {
                showFABMenu();
            } else {
                closeFABMenu();
            }
        }
    });

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();

            android.app.AlertDialog.Builder builder = new android.app.AlertDialog.Builder(getActivity());
            View dialogView = View.inflate(getActivity(), R.layout.dialog_edit_entry, null);

            final EditText edit_title = (EditText) dialogView.findViewById(R.id.note_title_input);
            edit_title.setHint(R.string.title_hint);

            final EditText edit_cont = (EditText) dialogView.findViewById(R.id.note_text_input);
            edit_cont.setHint(R.string.text_hint);

            builder.setView(dialogView);
            builder.setTitle(R.string.number_edit_entry);
            builder.setPositiveButton(R.string.toast_yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {

                    String inputTitle = edit_title.getText().toString().trim();
                    String inputCont = edit_cont.getText().toString().trim();

                    if (db.isExist(inputTitle)) {
                        Snackbar.make(lv, getString(R.string.toast_newTitle), Snackbar.LENGTH_LONG).show();
                    } else {
                        db.insert(inputTitle, inputCont, "", "", helper_main.createDate());
                        dialog.dismiss();
                        setRandomList();
                        Snackbar.make(lv, R.string.bookmark_added, Snackbar.LENGTH_SHORT).show();
                    }
                }
            });
            builder.setNegativeButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    dialog.cancel();
                }
            });

            final android.app.AlertDialog dialog2 = builder.create();
            // Display the custom alert dialog on interface
            dialog2.show();
            helper_main.showKeyboard(getActivity(), edit_title);
        }
    });

    fab2.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            closeFABMenu();
            Intent mainIntent = new Intent(getActivity(), Popup_courseList.class);
            mainIntent.setAction("courseList_random");
            startActivity(mainIntent);
        }
    });

    fab_dice.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            try {
                Random rand = new Random();
                final int n = rand.nextInt(lvItems.getCount());

                setAdapter(n);
                lvItems.setSelection(n - 1);

            } catch (NumberFormatException nfe) {
                nfe.printStackTrace();
            }
        }
    });

    //calling Notes_DbAdapter
    db = new Random_DbAdapter(getActivity());
    db.open();

    setRandomList();
    setHasOptionsMenu(true);

    return rootView;
}

From source file:org.onosproject.netconf.ctl.impl.NetconfSshdTestSubsystem.java

private boolean validateChunkedFraming(String reply) {
    String[] strs = reply.split(LF + HASH);
    int strIndex = 0;
    while (strIndex < strs.length) {
        String str = strs[strIndex];
        if ((str.equals(HASH + LF))) {
            return true;
        }/*from   www . j  av a 2s.com*/
        if (!str.equals("")) {
            try {
                if (str.equals(LF)) {
                    return false;
                }
                int len = Integer.parseInt(str.split(LF)[0]);
                if (str.split(MSGLEN_PART_REGEX_PATTERN)[1].getBytes("UTF-8").length != len) {
                    return false;
                }
            } catch (NumberFormatException e) {
                return false;
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }
        strIndex++;
    }
    return true;
}

From source file:com.google.android.gms.location.sample.geofencing.MainActivity.java

public void GetID() {

    List<NeighboringCellInfo> neighCell = null;
    TelephonyManager telManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    neighCell = telManager.getNeighboringCellInfo();
    for (int i = 0; i < neighCell.size(); i++) {
        try {//from  w w  w.ja  v  a 2s.  c om
            NeighboringCellInfo thisCell = neighCell.get(i);
            int thisNeighCID = thisCell.getCid();
            int thisNeighRSSI = thisCell.getRssi();
            Log.i("Info:", " cid:" + thisNeighCID + " - " + thisNeighRSSI);
        } catch (NumberFormatException e) {
            e.printStackTrace();
            NeighboringCellInfo thisCell = neighCell.get(i);
            Log.i("exception", neighCell.toString());
        }
    }
    String networkOperator = telManager.getNetworkOperator();
    String mcc = "not avl", mnc = "not avl";
    if (networkOperator != null) {
        mcc = networkOperator.substring(0, 3);
        mnc = networkOperator.substring(3);
    }
    Log.i("", "mcc:" + mcc);
    Log.i("", "mnc:" + mnc);
}

From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java

private int getIdFromUri(Uri uri) {
    int postId = -1;

    List<String> pathSegments = uri.getPathSegments();

    if ((pathSegments.size() == 5) && (pathSegments.get(0).equals(Const.INTENT_EXTRA_URL_PATH_POST_ID))) {

        try {//  ww  w .j  av a 2  s .c  om
            postId = Integer.parseInt(pathSegments.get(1));
            final int day = Integer.valueOf(pathSegments.get(2));
            final double time = Double.valueOf(pathSegments.get(3));
            final int duration = Integer.valueOf(pathSegments.get(4));

            final int hourOfDay = (int) time;
            final int minute = (int) ((time - hourOfDay) * 60);

            GregorianCalendar calendar = new GregorianCalendar();

            calendar.set(Calendar.DAY_OF_WEEK, day == 7 ? Calendar.SUNDAY : day + 1);
            calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
            calendar.set(Calendar.MINUTE, minute);

            parkingApp.setParkingCalendar(calendar);
            // parkingApp.setParkingTime(hourOfDay, minute);
            parkingApp.setParkingDuration(duration);
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
    }

    return postId;
}