List of usage examples for java.lang String subSequence
public CharSequence subSequence(int beginIndex, int endIndex)
From source file:com.mobileobservinglog.AvailableCatalogsTab.java
private String createDirectoryStructure(String root, String filepath) { //Cut the filename off the end of the path Log.d("JoeDebug", "Creating directory structure. Filepath passed in: " + filepath); int index = filepath.lastIndexOf("/"); String directoryPath = filepath.subSequence(0, index).toString(); File directoryBuilder = new File(root.toString() + directoryPath); directoryBuilder.mkdirs();//from w w w . j a v a 2 s . c o m Log.d("JoeDebug", "Created directory structure for " + directoryPath); return directoryPath; }
From source file:org.apache.james.jdkim.tagvalue.SignatureRecordImpl.java
/** * @see org.apache.james.jdkim.api.SignatureRecord#getHashMethod() */// w w w .j a va 2 s .c o m public CharSequence getHashMethod() { String a = getValue("a").toString(); int pHyphen = a.indexOf('-'); // TODO x-sig-a-tag-h = ALPHA *(ALPHA / DIGIT) if (pHyphen == -1) throw new IllegalStateException("Invalid hash method: " + a); return a.subSequence(pHyphen + 1, a.length()); }
From source file:com.contrastsecurity.ide.eclipse.ui.internal.model.EventsTab.java
private String getTypeName(String stacktrace) throws CoreException { int start = stacktrace.lastIndexOf('('); int end = stacktrace.indexOf(':'); if (start >= 0 && end > start) { String typeName = stacktrace.substring(start + 1, end); typeName = JavaCore.removeJavaLikeExtension(typeName); String qualifier = stacktrace.substring(0, start); start = qualifier.lastIndexOf('.'); if (start >= 0) { start = new String((String) qualifier.subSequence(0, start)).lastIndexOf('.'); if (start == -1) { start = 0;// w ww . j a va 2s. c om } } if (start >= 0) { qualifier = qualifier.substring(0, start); } if (qualifier.length() > 0) { typeName = qualifier + "." + typeName; } return typeName; } IStatus status = new Status(IStatus.ERROR, ContrastUIActivator.PLUGIN_ID, 0, "Unable to parse type name from stacktrace", null); throw new CoreException(status); }
From source file:org.apache.james.jdkim.tagvalue.SignatureRecordImpl.java
/** * @see org.apache.james.jdkim.api.SignatureRecord#getHashKeyType() *//*from ww w . j a va 2s . c om*/ public CharSequence getHashKeyType() { String a = getValue("a").toString(); int pHyphen = a.indexOf('-'); // TODO x-sig-a-tag-h = ALPHA *(ALPHA / DIGIT) if (pHyphen == -1) throw new IllegalStateException("Invalid hash algorythm (key type): " + a); return a.subSequence(0, pHyphen); }
From source file:com.ichi2.libanki.sync.MediaSyncer.java
public String sync() throws UnknownHttpResponseException, MediaSyncException { try {/*from w w w . jav a2 s . c o m*/ // check if there have been any changes // If we haven't built the media db yet, do so on this sync. See note at the top // of this class about this difference to the original. if (mCol.getMedia().needScan()) { mCon.publishProgress(R.string.sync_media_find); mCol.log("findChanges"); mCol.getMedia().findChanges(); } // begin session and check if in sync int lastUsn = mCol.getMedia().lastUsn(); JSONObject ret = mServer.begin(); int srvUsn = ret.getInt("usn"); if ((lastUsn == srvUsn) && !(mCol.getMedia().haveDirty())) { return "noChanges"; } // loop through and process changes from server mCol.log("last local usn is " + lastUsn); mDownloadCount = 0; while (true) { // Allow cancellation if (Connection.getIsCancelled()) { Timber.i("Sync was cancelled"); try { mServer.finish(); } catch (UnknownHttpResponseException e) { } throw new RuntimeException("UserAbortedSync"); } JSONArray data = mServer.mediaChanges(lastUsn); mCol.log("mediaChanges resp count: ", data.length()); if (data.length() == 0) { break; } List<String> need = new ArrayList<String>(); lastUsn = data.getJSONArray(data.length() - 1).getInt(1); for (int i = 0; i < data.length(); i++) { String fname = data.getJSONArray(i).getString(0); int rusn = data.getJSONArray(i).getInt(1); String rsum = data.getJSONArray(i).optString(2); Pair<String, Integer> info = mCol.getMedia().syncInfo(fname); String lsum = info.first; int ldirty = info.second; mCol.log(String.format("check: lsum=%s rsum=%s ldirty=%d rusn=%d fname=%s", TextUtils.isEmpty(lsum) ? "" : lsum.subSequence(0, 4), TextUtils.isEmpty(rsum) ? "" : rsum.subSequence(0, 4), ldirty, rusn, fname)); if (!TextUtils.isEmpty(rsum)) { // added/changed remotely if (TextUtils.isEmpty(lsum) || !lsum.equals(rsum)) { mCol.log("will fetch"); need.add(fname); } else { mCol.log("have same already"); } mCol.getMedia().markClean(Arrays.asList(fname)); } else if (!TextUtils.isEmpty(lsum)) { // deleted remotely if (ldirty != 0) { mCol.log("delete local"); mCol.getMedia().syncDelete(fname); } else { // conflict: local add overrides remote delete mCol.log("conflict; will send"); } } else { // deleted both sides mCol.log("both sides deleted"); mCol.getMedia().markClean(Arrays.asList(fname)); } } _downloadFiles(need); mCol.log("update last usn to " + lastUsn); mCol.getMedia().setLastUsn(lastUsn); // commits } // at this point, we're all up to date with the server's changes, // and we need to send our own boolean updateConflict = false; int toSend = mCol.getMedia().dirtyCount(); while (true) { Pair<File, List<String>> changesZip = mCol.getMedia().mediaChangesZip(); File zip = changesZip.first; try { List<String> fnames = changesZip.second; if (fnames.size() == 0) { break; } mCon.publishProgress(String.format( AnkiDroidApp.getAppResources().getString(R.string.sync_media_changes_count), toSend)); JSONArray changes = mServer.uploadChanges(zip); int processedCnt = changes.getInt(0); int serverLastUsn = changes.getInt(1); mCol.getMedia().markClean(fnames.subList(0, processedCnt)); mCol.log(String.format("processed %d, serverUsn %d, clientUsn %d", processedCnt, serverLastUsn, lastUsn)); if (serverLastUsn - processedCnt == lastUsn) { mCol.log("lastUsn in sync, updating local"); lastUsn = serverLastUsn; mCol.getMedia().setLastUsn(serverLastUsn); // commits } else { mCol.log("concurrent update, skipping usn update"); // commit for markClean mCol.getMedia().getDb().commit(); updateConflict = true; } toSend -= processedCnt; } finally { zip.delete(); } } if (updateConflict) { mCol.log("restart sync due to concurrent update"); return sync(); } int lcnt = mCol.getMedia().mediacount(); String sRet = mServer.mediaSanity(lcnt); if (sRet.equals("OK")) { return "OK"; } else { mCol.getMedia().forceResync(); return sRet; } } catch (JSONException e) { throw new RuntimeException(e); } }
From source file:Main.java
public static String getEllipsisedText(TextView textView) { try {/* w w w.j av a2 s .com*/ String text = textView.getText().toString(); int lines = textView.getLineCount(); int width = textView.getWidth(); int len = text.length(); Log.d("Test", "text-->" + text + "; lines-->" + lines + "; width-->" + width + ";len-->" + len); TextUtils.TruncateAt where = TextUtils.TruncateAt.END; TextPaint paint = textView.getPaint(); StringBuffer result = new StringBuffer(); int spos = 0, cnt, tmp, hasLines = 0; while (hasLines < lines - 1) { cnt = paint.breakText(text, spos, len, true, width, null); if (cnt >= len - spos) { result.append(text.substring(spos)); break; } tmp = text.lastIndexOf('\n', spos + cnt - 1); if (tmp >= 0 && tmp < spos + cnt) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { tmp = text.lastIndexOf(' ', spos + cnt - 1); if (tmp >= spos) { result.append(text.substring(spos, tmp + 1)); spos += tmp + 1; } else { result.append(text.substring(spos, cnt)); spos += cnt; } } hasLines++; } if (spos < len) { result.append(TextUtils.ellipsize(text.subSequence(spos, len), paint, (float) width, where)); } return result.toString(); } catch (Exception e) { e.printStackTrace(); } return null; }
From source file:de.huxhorn.lilith.log4j.xml.Log4jImportCallable.java
public Long call() throws Exception { if (!inputFile.isFile()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a file!"); }/* w w w. ja va2 s . c o m*/ if (!inputFile.canRead()) { throw new IllegalArgumentException("'" + inputFile.getAbsolutePath() + "' is not a readable!"); } long fileSize = inputFile.length(); setNumberOfSteps(fileSize); FileInputStream fis = new FileInputStream(inputFile); CountingInputStream cis = new CountingInputStream(fis); String fileName = inputFile.getName().toLowerCase(Locale.US); BufferedReader br; if (fileName.endsWith(".gz")) { br = new BufferedReader(new InputStreamReader(new GZIPInputStream(cis), StandardCharsets.UTF_8)); } else { br = new BufferedReader(new InputStreamReader(cis, StandardCharsets.UTF_8)); } StringBuilder builder = new StringBuilder(); result = 0; for (;;) { String line = br.readLine(); setCurrentStep(cis.getByteCount()); if (line == null) { evaluate(builder.toString()); break; } for (;;) { int closeIndex = line.indexOf(CLOSING_LOG4J_EVENT_TAG); if (closeIndex >= 0) { int endIndex = closeIndex + CLOSING_LOG4J_EVENT_TAG.length(); builder.append(line.subSequence(0, endIndex)); evaluate(builder.toString()); builder.setLength(0); line = line.substring(endIndex); } else { builder.append(line); builder.append("\n"); break; } } } return result; }
From source file:org.caleydo.data.importer.tcga.FirehoseProvider.java
private TCGAFileInfo filterColumns(TCGAFileInfo full, Pair<TCGAFileInfo, Boolean> sampled) { File in = full.getFile();/* w w w .j a va2s .c om*/ File out = new File(in.getParentFile(), "F" + in.getName()); TCGAFileInfo r = new TCGAFileInfo(out, full.getArchiveURL(), full.getSourceFileName()); if (out.exists() && !settings.isCleanCache()) return r; assert full != null; if (sampled == null || sampled.getFirst() == null) { log.severe("can't filter the full gene file: " + in + " - sampled not found"); return full; } // full: 1row, 2col // sampled: 3row, 3col Set<String> good = readGoodSamples(sampled.getFirst().getFile()); if (good == null) return full; try (BufferedReader fin = new BufferedReader(new FileReader(in)); PrintWriter w = new PrintWriter(out)) { String[] header = fin.readLine().split("\t"); BitSet bad = filterCols(header, good); { StringBuilder b = new StringBuilder(); for (int i = bad.nextSetBit(0); i >= 0; i = bad.nextSetBit(i + 1)) b.append(' ').append(header[i]); log.warning("remove bad samples of " + in + ":" + b); } w.append(header[0]); for (int i = 1; i < header.length; ++i) { if (bad.get(i)) continue; w.append('\t').append(header[i]); } String line; while ((line = fin.readLine()) != null) { w.println(); int t = line.indexOf('\t'); w.append(line.subSequence(0, t)); int prev = t; int i = 1; for (t = line.indexOf('\t', t + 1); t >= 0; t = line.indexOf('\t', t + 1), ++i) { if (!bad.get(i)) w.append(line.subSequence(prev, t)); prev = t; } if (!bad.get(i)) w.append(line.subSequence(prev, line.length())); } } catch (IOException e) { log.log(Level.SEVERE, "can't filter full file: " + in, e); } return r; }
From source file:org.openmrs.hl7.HL7Util.java
/** * Converts an HL7 time into a java.util.Date object. Since the java.util.Date object cannot * store just the time, the date will remain at the epoch (e.g., January 1, 1970). Time more * precise than microseconds is ignored. * * @param s HL7 time to be converted//from w w w . j av a2 s . com * @return Date object set to time specified by HL7 * @throws HL7Exception * @should fail on 197804110615 * @should handle 0615 * @should handle 061538 * @should handle 061538.1 * @should handle 061538.12 * @should handle 061538.123 * @should handle 061538.1234 * @should handle 061538-0300 */ public static Date parseHL7Time(String s) throws HL7Exception { String timeZoneOffset = getTimeZoneOffset(s, new Date()); s = s.replace(timeZoneOffset, ""); // remove the timezone from the string StringBuffer timeString = new StringBuffer(); if (s.length() < 2 || s.length() > 16) { throw new HL7Exception("Invalid time format '" + s + "'"); } timeString.append(s.substring(0, 2)); // hour if (s.length() >= 4) { timeString.append(s.substring(2, 4)); // minute } else { timeString.append("00"); } if (s.length() >= 6) { timeString.append(s.substring(4, 6)); // seconds } else { timeString.append("00"); } if (s.length() >= 7 && s.charAt(6) != '.') { // decimal point throw new HL7Exception("Invalid time format '" + s + "'"); } else { timeString.append("."); } if (s.length() >= 8) { timeString.append(s.substring(7, 8)); // tenths } else { timeString.append("0"); } if (s.length() >= 9) { timeString.append(s.substring(8, 9)); // hundredths } else { timeString.append("0"); } if (s.length() >= 10) { timeString.append(s.subSequence(9, 10)); // milliseconds } else { timeString.append("0"); } // Parse timezone (optional in HL7 format) timeString.append(timeZoneOffset); Date date; try { date = new SimpleDateFormat(TIME_FORMAT).parse(timeString.toString()); } catch (ParseException e) { throw new HL7Exception("Invalid time format: '" + s + "' [" + timeString + "]", e); } return date; }
From source file:com.mobilefirst.fiberlink.WebServiceRequest.java
/** * formulateGetURI method formulates the get request URI * @param URI: uri to be formulated/*from w w w .j a va 2 s .com*/ * @param params: uri to be formulated using params * @return returns the formulated uri * @throws Exception */ public String formulateGetURI(String URI, Hashtable<String, String> params) throws Exception { String newURI = null; String postURI = "?"; try { Enumeration<String> keys = params.keys(); while (keys.hasMoreElements()) { String key = keys.nextElement(); postURI = postURI + key + "=" + params.get(key) + "&"; } postURI = (String) postURI.subSequence(0, postURI.length() - 1); newURI = URI + postURI.replaceAll(" ", "%20"); //TODO - Further URL Encoding } catch (Exception e) { throw new Exception(e); } return newURI; }