@Override protected void onProgressUpdate(Integer... values) { try { //LogUtils.i(TAG, "progress:" + ((tmp + loaded) / Float.valueOf(totals) * 100) + "tmp:" + tmp + " load=:" + loaded + " total:" + totals); long c = System.currentTimeMillis(); if (mNotify != null && c - time > 800) { time = c; if (!mNotify.hasDeleteContent()) mNotify.setDelecte(buildCancelContent(mDownLoadTask.getContext().getApplicationContext(), mDownLoadTask.getId())); int mProgress = (int) ((tmp + loaded) / Float.valueOf(totals) * 100); mNotify.setContentText(String.format(mDownLoadTask.getDownLoadMsgConfig().getLoading(), mProgress + "%")); mNotify.setProgress(100, mProgress, false); } } catch (UnknownFormatConversionException e) { e.printStackTrace(); } long current = System.currentTimeMillis(); used = current - begin; }
private char conversion(String s) { c = s.charAt(0); if (!dt) { if (!Conversion.isValid(c)) throw new UnknownFormatConversionException(String.valueOf(c)); if (Character.isUpperCase(c)) f.add(Flags.UPPERCASE); c = Character.toLowerCase(c); if (Conversion.isText(c)) index = -2; } if (s.length() == 2) { c2 = s.charAt(1); } return c; }
public String getStatistics() { try { double returnedPct = (bytesRead > 0 ? (100.0 * bytesReturned / bytesRead) : 100.0); return String .format("Bytes read: %12d\n returned: %12d ( %3.2f %% )", bytesRead, bytesReturned, returnedPct) + String.format("\nReads past the end: %3d", nbReadsPastEnd) + String.format("\nReads forcing re-fetching of an earlier block: %3d", nbGoingBack) // A near-hit is when we're already fetching the data the user is asking for, // but we're not done loading it in. + String .format("\nCache\n hits: %12d\n near-hits: %12d\n misses: %12d", nbHit, nbNearHit, nbMiss); } catch (UnknownFormatConversionException x) { // let's not crash the whole program, instead just return no info return "(error while formatting statistics)"; } }
private void checkText() { if (precision != -1) throw new IllegalFormatPrecisionException(precision); switch (c) { case Conversion.PERCENT_SIGN: if (f.valueOf() != Flags.LEFT_JUSTIFY.valueOf() && f.valueOf() != Flags.NONE.valueOf()) throw new IllegalFormatFlagsException(f.toString()); // '-' requires a width if (width == -1 && f.contains(Flags.LEFT_JUSTIFY)) throw new MissingFormatWidthException(toString()); break; case Conversion.LINE_SEPARATOR: if (width != -1) throw new IllegalFormatWidthException(width); if (f.valueOf() != Flags.NONE.valueOf()) throw new IllegalFormatFlagsException(f.toString()); break; default: throw new UnknownFormatConversionException(String.valueOf(c)); } }
@Test(timeout = 4000) public void test06() throws Throwable { CoreDbConfiguration coreDbConfiguration0 = new CoreDbConfiguration(); CoreDbConfiguration.JDBC_URL = "%jj;97ATvw)UDwSM|"; // Undeclared exception! try { coreDbConfiguration0.getCoreJdbcURL(); fail("Expecting exception: UnknownFormatConversionException"); } catch (UnknownFormatConversionException e) { // // Conversion = 'j' // assertThrownBy("java.util.Formatter$FormatSpecifier", e); } }
@Test(timeout = 4000) public void test09() throws Throwable { CoreDbConfiguration coreDbConfiguration0 = new CoreDbConfiguration(); coreDbConfiguration0.corePassword = "jdbc:postgresql://null:183/core"; CoreDbConfiguration.JDBC_URL = ""; CoreDbConfiguration.JDBC_URL = "3B=3WSv`LLpD)\"E<%"; // Undeclared exception! try { coreDbConfiguration0.getCoreConnection(); fail("Expecting exception: UnknownFormatConversionException"); } catch (UnknownFormatConversionException e) { // // Conversion = '%' // assertThrownBy("java.util.Formatter", e); } }
@Test(expected = UnknownFormatConversionException.class) public void failsForInvalidPattern() throws IOException { new FormattedText( new TextOf("%%. Formatted %$"), new ListOf<>(1, "invalid") ).asString(); }
@Override protected String doInBackground(InputStream... params) { try { parseELF(callback, params[0]); } catch (UnknownFormatConversionException | IOException e) { e.printStackTrace(); return "failed"; } return getString(R.string.success); }
/** * Apply formatting rule corresponding to given identifier * @param identifier Symbolic identifier following '$' * @param arg Object argument * @return Formatted string * @throws IllegalFormatException Unable to format given object argument * according to specified rule */ public String applyRule(String identifier, Object arg) throws IllegalFormatException { FormattingRule rule = formattingRules.get(identifier); if (rule == null) { throw new UnknownFormatConversionException("Formatting rule not available corresponding " + "to given identifier " + identifier); } return rule.apply(identifier, arg); }
public Long fromString(String string) { if (string == null || string.isEmpty()) return null; Matcher matcher = ValueWithUnit.matcher(string.toLowerCase()); if (!matcher.matches()) throw new UnknownFormatConversionException(String.format("Invalid format %s", string)); Long value = Long.valueOf(matcher.group(1)); String unit = matcher.group(2); if (unit.isEmpty()) return value; int index = units.toLowerCase().indexOf(unit.toLowerCase()); return value * (long) Math.pow(getBase(), (double) index + 1); }
public static String getFormattedString(Context context, @StringRes int resId, Object... formatArgs) { String result; final Resources resources = context.getResources(); try { result = resources.getString(resId, formatArgs); }catch (UnknownFormatConversionException ex){ final String resourceEntryName = resources.getResourceEntryName(resId); final String displayLanguage = Locale.getDefault().getDisplayLanguage(); Logger.e("UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); Crashlytics.log(3, "UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); result = resources.getString(resId); } return result; }
public static String getFormattedString(@StringRes int resId, Resources resources, Object... formatArgs) { String result; try { result = resources.getString(resId, formatArgs); } catch (UnknownFormatConversionException ex) { final String resourceEntryName = resources.getResourceEntryName(resId); final String displayLanguage = Locale.getDefault() .getDisplayLanguage(); Logger.e("UnknownFormatConversion", "String: " + resourceEntryName + " Locale: " + displayLanguage); result = ResourseU.getString(resId, resources); } return result; }
@Override public void processFile(String filePath, String media) { mFabMenu.onBackPressed(); mUploadProgress.setVisibility(View.VISIBLE); File file = new File(Util.getPath(getApplicationContext(), filePath)); if (file.exists()) { Observable.create(new Observable.OnSubscribe<String[]>() { @Override public void call(Subscriber<? super String[]> subscriber) { String str = Util.decodeFile(file); if (str != null) { int chunkSize = 4 * 8 * 1024; subscriber.onNext(Util.splitStringBySize(str, chunkSize).toArray(new String[0])); subscriber.onCompleted(); } else { subscriber.onError(new UnknownFormatConversionException("failed to convert " + filePath + " to string")); } } }) .subscribeOn(Schedulers.computation()) .observeOn(AndroidSchedulers.mainThread()) .subscribe(new Subscriber<String[]>() { @Override public void onCompleted() { } @Override public void onError(Throwable e) { mUploadProgress.setVisibility(View.GONE); } @Override public void onNext(String[] strings) { uploadFile(file.getName(), media, file.length(), strings); } }); } }
/** * Get the time at which the leased subscription will expire, or has expired. * * @return The expiry date */ public Date getExpiry() { String dateTime = getFieldValue(SubscribeOptionFields.expire); try { return XmppDateTime.parseDate(dateTime); } catch (ParseException e) { UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime); exc.initCause(e); throw exc; } }
public static char[] determineAddressFieldsToDisplay(String paramString) throws UnknownFormatConversionException { if (TextUtils.isEmpty(paramString)) { throw new UnknownFormatConversionException("Cannot convert null/empty formats"); } ArrayList localArrayList1 = new ArrayList(); Iterator localIterator1 = getFormatSubStrings(paramString).iterator(); while (localIterator1.hasNext()) { String str = (String)localIterator1.next(); if ((str.matches("%.")) && (!str.equals("%n"))) { localArrayList1.add(Character.valueOf(str.charAt(1))); } } ArrayList localArrayList2 = new ArrayList(); Iterator localIterator2 = localArrayList1.iterator(); while (localIterator2.hasNext()) { char c = ((Character)localIterator2.next()).charValue(); if (c == 'A') { localArrayList2.add(Character.valueOf('1')); localArrayList2.add(Character.valueOf('2')); localArrayList2.add(Character.valueOf('3')); } else { localArrayList2.add(Character.valueOf(c)); } } char[] arrayOfChar = new char[localArrayList2.size()]; for (int i = 0; i < arrayOfChar.length; i++) { arrayOfChar[i] = ((Character)localArrayList2.get(i)).charValue(); } return arrayOfChar; }
private static ArrayList<String> getFormatSubStrings(String paramString) throws UnknownFormatConversionException { ArrayList localArrayList = new ArrayList(); int i = 0; char[] arrayOfChar = paramString.toCharArray(); int j = arrayOfChar.length; int k = 0; if (k < j) { char c = arrayOfChar[k]; if (i != 0) { i = 0; if ("%n".equals("%" + c)) { localArrayList.add("%n"); } } for (;;) { k++; break; if (!AddressField.exists(c)) { throw new UnknownFormatConversionException("Cannot determine AddressField for '" + c + "'"); } localArrayList.add("%" + c); i = 0; continue; if (c == '%') { i = 1; } else { localArrayList.add(Character.toString(c)); } } } return localArrayList; }
/** * Get the time at which the leased subscription will expire, or has expired. * * @return The expiry date */ public Date getExpiry() { String dateTime = getFieldValue(SubscribeOptionFields.expire); try { return format.parse(dateTime); } catch (ParseException e) { UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime); exc.initCause(e); throw exc; } }
private void checkText(String s) { int idx; // If there are any '%' in the given string, we got a bad format // specifier. if ((idx = s.indexOf('%')) != -1) { char c = (idx > s.length() - 2 ? '%' : s.charAt(idx + 1)); throw new UnknownFormatConversionException(String.valueOf(c)); } }
FormatSpecifier(F3Formatter formatter, String[] sa) { this.formatter = formatter; int idx = 0; index(sa[idx++]); flags(sa[idx++]); width(sa[idx++]); precision(sa[idx++]); if (sa[5] != null) { dt = true; if (sa[5].equals("T")) f.add(Flags.UPPERCASE); conversion(sa[6]); } else { conversion(sa[idx]); } if (dt) checkDateTime(); else if (Conversion.isGeneral(c)) checkGeneral(); else if (Conversion.isCharacter(c)) checkCharacter(); else if (Conversion.isInteger(c)) checkInteger(); else if (Conversion.isFloat(c)) checkFloat(); else if (Conversion.isText(c)) checkText(); else throw new UnknownFormatConversionException(String.valueOf(c)); }
private void checkDateTime() { if (precision != -1) throw new IllegalFormatPrecisionException(precision); if (!DateTime.isValid(c, c2)) throw new UnknownFormatConversionException("t" + c); checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES); // '-' requires a width if (width == -1 && f.contains(Flags.LEFT_JUSTIFY)) throw new MissingFormatWidthException(toString()); }
/** * Get the time at which the leased subscription will expire, or has expired. * * @return The expiry date */ public Date getExpiry() { String dateTime = getFieldValue(SubscribeOptionFields.expire); try { return StringUtils.parseDate(dateTime); } catch (ParseException e) { UnknownFormatConversionException exc = new UnknownFormatConversionException(dateTime); exc.initCause(e); throw exc; } }
public GameSave<?> parse(String string) { String[] tokens = string.split("_"); if (tokens.length == 1 && tokens[0].compareToIgnoreCase(GBA.Save.Type.NONE.toString()) == 0) return new GBA.Save(GBA.Save.Type.NONE); else if (tokens.length >= 2) { if (tokens.length > 2) tokens[1] = tokens[2]; for (GBA.Save.Type type : GBA.Save.Type.values()) { if (tokens[0].toLowerCase().contains(type.toString().toLowerCase())) { Version[] versions = GBA.Save.valuesForType(type); for (Version version : versions) { if (tokens[1].contains(version.toString())) return new GBA.Save(type, version); } throw new UnknownFormatConversionException("Unable to parse GBA save: "+string); } } } return new GBA.Save(GBA.Save.Type.NONE); }
public GameSave<?> parse(String string) { if (string.equals("TBC")) return new NDS.Save(NDS.Save.Type.TBC); else if (string.equals("None")) return new NDS.Save(NDS.Save.Type.NONE); String[] tokens = string.split(" - "); tokens = Arrays.stream(tokens).map(String::trim).map(String::toLowerCase).toArray(String[]::new); NDS.Save.Type type = null; long multiplier = 0; if (tokens[0].equals("flash")) type = NDS.Save.Type.FLASH; else if (tokens[0].equals("eeprom")) type = NDS.Save.Type.EEPROM; else throw new UnknownFormatConversionException("Unable to parse NDS save: "+string); if (tokens[1].endsWith("kbit")) multiplier = RomSize.KBIT; else if (tokens[1].endsWith("mbit")) multiplier = RomSize.MEGABIT; else throw new UnknownFormatConversionException("Unable to parse NDS save: "+string); String ntoken = tokens[1].substring(0, tokens[1].length() - 4).trim(); multiplier *= Integer.valueOf(ntoken); return new NDS.Save(type, multiplier); }
/** * Get the time at which the leased subscription will expire, or has * expired. * * @return The expiry date */ public Date getExpiry() { String dateTime = getFieldValue(SubscribeOptionFields.expire); try { return format.parse(dateTime); } catch (ParseException e) { UnknownFormatConversionException exc = new UnknownFormatConversionException( dateTime); exc.initCause(e); throw exc; } }
/** * @tests java.util.UnknownFormatConversionException#UnknownFormatConversionException(String) */ public void test_unknownFormatConversionException() { // RI 5.0 will not throw NullPointerException, it is the bug according // to spec. try { new UnknownFormatConversionException(null); fail("should throw NullPointerExcepiton"); } catch (NullPointerException e) { } }
/** * @tests java.util.UnknownFormatConversionException#getConversion() */ public void test_getConversion() { String s = "MYTESTSTRING"; UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( s); assertEquals(s, UnknownFormatConversionException.getConversion()); }
/** * @tests java.util.UnknownFormatConversionException#getMessage() */ public void test_getMessage() { String s = "MYTESTSTRING"; UnknownFormatConversionException UnknownFormatConversionException = new UnknownFormatConversionException( s); assertTrue(null != UnknownFormatConversionException.getMessage()); }
public void assertDeserialized(Serializable initial, Serializable deserialized) { SerializationTest.THROWABLE_COMPARATOR.assertDeserialized(initial, deserialized); UnknownFormatConversionException initEx = (UnknownFormatConversionException) initial; UnknownFormatConversionException desrEx = (UnknownFormatConversionException) deserialized; assertEquals("Conversion", initEx.getConversion(), desrEx .getConversion()); }
/** * @tests serialization/deserialization compatibility with RI. */ public void testSerializationCompatibility() throws Exception { SerializationTest.verifyGolden(this, new UnknownFormatConversionException("MYTESTSTRING"), exComparator); }
private char conversion(String s) { c = s.charAt(0); if (!dt) { if (!Conversion.isValid(c)) throw new UnknownFormatConversionException(String.valueOf(c)); if (Character.isUpperCase(c)) f.add(Flags.UPPERCASE); c = Character.toLowerCase(c); if (Conversion.isText(c)) index = -2; } return c; }
FormatSpecifier(String source, String[] sa) throws FormatFlagsConversionMismatchException, FormatterNumberFormatException { int idx = 0; this.source = source; index(sa[idx++]); flags(sa[idx++]); width(sa[idx++]); precision(sa[idx++]); if (sa[idx] != null) { dt = true; if (sa[idx].equals("T")) f.add(Flags.UPPERCASE); } conversion(sa[++idx]); if (dt) checkDateTime(); else if (Conversion.isGeneral(c)) checkGeneral(); else if (Conversion.isCharacter(c)) checkCharacter(); else if (Conversion.isInteger(c)) checkInteger(); else if (Conversion.isFloat(c)) checkFloat(); else if (Conversion.isText(c)) checkText(); else throw new UnknownFormatConversionException(String.valueOf(c)); }
private void checkDateTime() throws FormatFlagsConversionMismatchException { if (precision != -1) throw new IllegalFormatPrecisionException(precision); if (!DateTime.isValid(c)) throw new UnknownFormatConversionException("t" + c); checkBadFlags(Flags.ALTERNATE, Flags.PLUS, Flags.LEADING_SPACE, Flags.ZERO_PAD, Flags.GROUP, Flags.PARENTHESES); // '-' requires a width if (width == -1 && f.contains(Flags.LEFT_JUSTIFY)) throw new MissingFormatWidthException(toString()); }
private static void checkText(String s) { int idx; // If there are any '%' in the given string, we got a bad format // specifier. if ((idx = s.indexOf('%')) != -1) { char c = (idx > s.length() - 2 ? '%' : s.charAt(idx + 1)); throw new UnknownFormatConversionException(String.valueOf(c)); } }
/** * @tests java.util.UnknownFormatConversionException#UnknownFormatConversionException(String) */ public void test_unknownFormatConversionException() { // RI 5.0 will not throw NullPointerException, it is the bug according // to spec. try { new UnknownFormatConversionException(null); } catch (NullPointerException e) { fail("should not throw NullPointerExcepiton"); } }