use of java.util.UnknownFormatConversionException in project azure-tools-for-java by Microsoft.
the class AdlUri method parse.
public static AdlUri parse(final String adlUri) {
Matcher matcher;
if (StringUtils.startsWithIgnoreCase(adlUri, "adl")) {
matcher = ADL_URI_PATTERN.matcher(adlUri);
} else if (StringUtils.startsWithIgnoreCase(adlUri, "http")) {
matcher = HTTP_URI_PATTERN.matcher(adlUri);
} else {
throw new UnknownFormatConversionException("Unsupported Azure ADLS Gen 1 URI Scheme: " + adlUri);
}
if (!matcher.matches()) {
throw new UnknownFormatConversionException("Unmatched Azure ADLS Gen 1 URI: " + adlUri);
}
final AdlUri uri = new AdlUri(URI.create(adlUri));
uri.storageName.set(matcher.group("storageName"));
final String pathMatched = matcher.group("path");
final String relativePathMatched = URI.create("/" + (pathMatched == null ? "" : pathMatched)).getPath();
uri.path.set(URI.create(relativePathMatched));
return uri;
}
use of java.util.UnknownFormatConversionException in project binnavi by google.
the class CBinExportImporter method createIdaProcess.
/**
* Creates the IDA Pro process that is used to export the data from the IDB file to the database.
*
* @param idaExe The location of the IDA Pro executable.
* @param idbFileName The location of the IDB file to import.
* @param host Host of the database.
* @param port Port of the database.
* @param user Name of the user used to connect to the database.
* @param password Password of the user.
* @param name Name of the database to connect to.
*
* @return The spawned IDA Pro process.
*
* @throws IdaException Thrown if the IDA Pro process could not be created.
*/
private static Process createIdaProcess(final String idaExe, final String idbFileName, final String host, final int port, final String user, final String password, final String name) throws IdaException {
final String tempPath = SystemHelpers.getTempDirectory();
final File idcFile = new File(tempPath + BINEXPORT_IDC_FILE);
try {
if (!idcFile.exists()) {
idcFile.createNewFile();
}
FileWriter fw = new FileWriter(idcFile.getAbsoluteFile());
BufferedWriter bw = new BufferedWriter(fw);
bw.write(BINEXPORT_IDC_FILE_CONTENT);
bw.close();
} catch (final IOException exception) {
CUtilityFunctions.logException(exception);
}
final String idcPath = idcFile.getAbsolutePath();
// Setup the invocation of the IDA to SQL exporter
final ProcessBuilder processBuilder = new ProcessBuilder(idaExe, "-A", "-OExporterHost:" + host, "-OExporterPort:" + port, "-OExporterUser:" + user, "-OExporterPassword:" + password, "-OExporterDatabase:" + name, "-OExporterSchema:public", IdaHelpers.getSArgument(idcPath, SystemHelpers.isRunningWindows()), idbFileName);
// Now launch the exporter to export the IDB to the database
try {
Process processInfo = null;
processBuilder.redirectErrorStream(true);
processInfo = processBuilder.start();
// Java manages the streams internally - if they are full, the process blocks, i.e. IDA
// hangs, so we need to consume them.
final BufferedReader reader = new BufferedReader(new InputStreamReader(processInfo.getInputStream()));
@SuppressWarnings("unused") String line;
try {
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
} catch (final IOException exception) {
reader.close();
}
reader.close();
return processInfo;
} catch (final Exception exception) {
try {
CUtilityFunctions.logException(exception);
} catch (final UnknownFormatConversionException e) {
// Some Windows error messages contain %1 characters.
}
throw new IdaException("E00210: Failed attempting to launch the importer with IDA: " + exception, exception);
}
}
use of java.util.UnknownFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerConversionException.
/**
* java.util.Formatter#format(String, Object...) for BigInteger
* conversion exception
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerConversionException() {
Formatter f = null;
final String[] flagsConversionMismatches = { "%#d", "%,o", "%,x", "%,X" };
for (int i = 0; i < flagsConversionMismatches.length; i++) {
try {
f = new Formatter(Locale.CHINA);
f.format(flagsConversionMismatches[i], new BigInteger("1"));
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingFormatWidths = { "%-0d", "%0d", "%-d", "%-0o", "%0o", "%-o", "%-0x", "%0x", "%-x", "%-0X", "%0X", "%-X" };
for (int i = 0; i < missingFormatWidths.length; i++) {
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], new BigInteger("1"));
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
final String[] illFlags = { "%+ d", "%-08d", "%+ o", "%-08o", "%+ x", "%-08x", "%+ X", "%-08X" };
for (int i = 0; i < illFlags.length; i++) {
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], new BigInteger("1"));
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
}
final String[] precisionExceptions = { "%.4d", "%2.5o", "%8.6x", "%11.17X" };
for (int i = 0; i < precisionExceptions.length; i++) {
try {
f = new Formatter(Locale.US);
f.format(precisionExceptions[i], new BigInteger("1"));
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
}
f = new Formatter(Locale.US);
try {
f.format("%D", new BigInteger("1"));
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
f = new Formatter(Locale.US);
try {
f.format("%O", new BigInteger("1"));
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
try {
f = new Formatter();
f.format("%010000000000000000000000000000000001d", new BigInteger("1"));
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
use of java.util.UnknownFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_ArgIndex.
/**
* java.util.Formatter#format(String, Object...) for argument index
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_ArgIndex() {
Formatter formatter = new Formatter(Locale.US);
formatter.format("%1$s%2$s%3$s%4$s%5$s%6$s%7$s%8$s%9$s%11$s%10$s", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
assertEquals("1234567891110", formatter.toString());
formatter = new Formatter(Locale.JAPAN);
formatter.format("%0$s", "hello");
assertEquals("hello", formatter.toString());
try {
formatter = new Formatter(Locale.US);
formatter.format("%-1$s", "1", "2");
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
try {
formatter = new Formatter(Locale.US);
formatter.format("%$s", "hello", "2");
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
try {
Formatter f = new Formatter(Locale.US);
f.format("%", "string");
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
formatter = new Formatter(Locale.FRANCE);
formatter.format("%1$s%2$s%3$s%4$s%5$s%6$s%7$s%8$s%<s%s%s%<s", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11");
assertEquals("123456788122", formatter.toString());
formatter = new Formatter(Locale.FRANCE);
formatter.format("xx%1$s22%2$s%s%<s%5$s%<s&%7$h%2$s%8$s%<s%s%s%<ssuffix", "1", "2", "3", "4", "5", "6", 7, "8", "9", "10", "11");
assertEquals("xx12221155&7288233suffix", formatter.toString());
try {
formatter.format("%<s", "hello");
fail("should throw MissingFormatArgumentException");
} catch (MissingFormatArgumentException e) {
// expected
}
formatter = new Formatter(Locale.US);
try {
formatter.format("%123$s", "hello");
fail("should throw MissingFormatArgumentException");
} catch (MissingFormatArgumentException e) {
// expected
}
formatter = new Formatter(Locale.US);
try {
// 2147483648 is the value of Integer.MAX_VALUE + 1
formatter.format("%2147483648$s", "hello");
fail("should throw MissingFormatArgumentException");
} catch (MissingFormatArgumentException e) {
// expected
}
try {
// 2147483647 is the value of Integer.MAX_VALUE
formatter.format("%2147483647$s", "hello");
fail("should throw MissingFormatArgumentException");
} catch (MissingFormatArgumentException e) {
// expected
}
formatter = new Formatter(Locale.US);
try {
formatter.format("%s%s", "hello");
fail("should throw MissingFormatArgumentException");
} catch (MissingFormatArgumentException e) {
// expected
}
formatter = new Formatter(Locale.US);
formatter.format("$100", 100);
assertEquals("$100", formatter.toString());
formatter = new Formatter(Locale.UK);
formatter.format("%01$s", "string");
assertEquals("string", formatter.toString());
}
use of java.util.UnknownFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for BigInteger
* exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder() {
Formatter f = null;
BigInteger big = new BigInteger("100");
/*
* Order summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* IllegalFormatPrecisionException > IllegalFormatConversionException >
* FormatFlagsConversionMismatchException
*
*/
f = new Formatter(Locale.US);
try {
f.format("%(o", false);
fail();
} catch (FormatFlagsConversionMismatchException expected) {
} catch (IllegalFormatConversionException expected) {
}
try {
f.format("%.4o", false);
fail();
} catch (IllegalFormatPrecisionException expected) {
} catch (IllegalFormatConversionException expected) {
}
try {
f.format("%+ .4o", big);
fail();
} catch (IllegalFormatPrecisionException expected) {
} catch (IllegalFormatFlagsException expected) {
}
try {
f.format("%+ -o", big);
fail();
} catch (MissingFormatWidthException expected) {
} catch (IllegalFormatFlagsException expected) {
}
try {
f.format("%-O", big);
fail();
} catch (MissingFormatWidthException expected) {
} catch (UnknownFormatConversionException expected) {
}
}
Aggregations