use of java.util.InputMismatchException in project j2objc by google.
the class InputMismatchExceptionTest method test_ConstructorLjava_lang_String.
/**
* java.util.InputMismatchException#InputMismatchException(String)
*/
public void test_ConstructorLjava_lang_String() {
InputMismatchException exception = new InputMismatchException(ERROR_MESSAGE);
assertNotNull(exception);
assertEquals(ERROR_MESSAGE, exception.getMessage());
}
use of java.util.InputMismatchException in project orientdb by orientechnologies.
the class OServerCommandPostImportRecords method execute.
@Override
public boolean execute(final OHttpRequest iRequest, OHttpResponse iResponse) throws Exception {
final String[] urlParts = checkSyntax(iRequest.url, 4, "Syntax error: importRecords/<database>/<format>/<class>[/<separator>][/<string-delimiter>][/<locale>]");
final long start = System.currentTimeMillis();
iRequest.data.commandInfo = "Import records";
ODatabaseDocument db = getProfiledDatabaseInstance(iRequest);
try {
final OClass cls = db.getMetadata().getSchema().getClass(urlParts[3]);
if (cls == null)
throw new IllegalArgumentException("Class '" + urlParts[3] + " is not defined");
if (iRequest.content == null)
throw new IllegalArgumentException("Empty content");
if (urlParts[2].equalsIgnoreCase("csv")) {
final char separator = urlParts.length > 4 ? urlParts[4].charAt(0) : CSV_SEPARATOR;
final char stringDelimiter = urlParts.length > 5 ? urlParts[5].charAt(0) : CSV_STR_DELIMITER;
final Locale locale = urlParts.length > 6 ? new Locale(urlParts[6]) : Locale.getDefault();
final BufferedReader reader = new BufferedReader(new StringReader(iRequest.content));
String header = reader.readLine();
if (header == null || (header = header.trim()).length() == 0)
throw new InputMismatchException("Missing CSV file header");
final List<String> columns = OStringSerializerHelper.smartSplit(header, separator);
for (int i = 0; i < columns.size(); ++i) columns.set(i, OIOUtils.getStringContent(columns.get(i)));
int imported = 0;
int errors = 0;
final StringBuilder output = new StringBuilder(1024);
int line = 0;
int col = 0;
String column = "?";
String parsedCell = "?";
final NumberFormat numberFormat = NumberFormat.getNumberInstance(locale);
for (line = 2; reader.ready(); line++) {
try {
final String parsedRow = reader.readLine();
if (parsedRow == null)
break;
final ODocument doc = new ODocument(cls);
final String row = parsedRow.trim();
final List<String> cells = OStringSerializerHelper.smartSplit(row, CSV_SEPARATOR);
for (col = 0; col < columns.size(); ++col) {
parsedCell = cells.get(col);
column = columns.get(col);
String cellValue = parsedCell.trim();
if (cellValue.length() == 0 || cellValue.equalsIgnoreCase("null"))
continue;
Object value;
if (cellValue.length() >= 2 && cellValue.charAt(0) == stringDelimiter && cellValue.charAt(cellValue.length() - 1) == stringDelimiter)
value = OIOUtils.getStringContent(cellValue);
else {
try {
value = numberFormat.parse(cellValue);
} catch (Exception e) {
value = ORecordSerializerCSVAbstract.getTypeValue(cellValue);
}
}
doc.field(columns.get(col), value);
}
doc.save();
imported++;
} catch (Exception e) {
errors++;
output.append(String.format("#%d: line %d column %s (%d) value '%s': '%s'\n", errors, line, column, col, parsedCell, e.toString()));
}
}
final float elapsed = (System.currentTimeMillis() - start) / 1000;
String message = String.format("Import of records of class '%s' completed in %5.3f seconds. Line parsed: %d, imported: %d, error: %d\nDetailed messages:\n%s", cls.getName(), elapsed, line, imported, errors, output);
iResponse.send(OHttpUtils.STATUS_CREATED_CODE, OHttpUtils.STATUS_CREATED_DESCRIPTION, OHttpUtils.CONTENT_TEXT_PLAIN, message, null);
return false;
} else
throw new UnsupportedOperationException("Unsupported format on importing record. Available formats are: csv");
} finally {
if (db != null)
db.close();
}
}
use of java.util.InputMismatchException in project open-kilda by telstra.
the class TraffExamServiceImpl method initializePools.
@PostConstruct
void initializePools() {
baseUrl = labEndpoint + "/api/" + topology.getLabId() + "/traffgen/";
hostsPool = new ConcurrentHashMap<>();
for (TraffGen traffGen : topology.getActiveTraffGens()) {
URI controlEndpoint;
try {
controlEndpoint = new URI(traffGen.getControlEndpoint());
} catch (URISyntaxException e) {
throw new IllegalArgumentException(String.format("Invalid traffGen(%s) REST endpoint address \"%s\": %s", traffGen.getName(), traffGen.getControlEndpoint(), e.getMessage()), e);
}
UUID id = UUID.randomUUID();
Host host = new Host(id, traffGen.getIfaceName(), controlEndpoint, traffGen.getName());
try {
restTemplate.headForHeaders(makeHostUri(host).path("endpoint").build());
} catch (RestClientException ex) {
throw new IllegalArgumentException(String.format("The traffGen(%s) REST endpoint address \"%s\" can't be reached: %s", traffGen.getName(), traffGen.getControlEndpoint(), ex.getMessage()), ex);
}
hostsPool.put(id, host);
}
TraffGenConfig config = topology.getTraffGenConfig();
Inet4Network network;
try {
network = new Inet4Network((Inet4Address) Inet4Address.getByName(config.getAddressPoolBase()), config.getAddressPoolPrefixLen());
} catch (Inet4ValueException | UnknownHostException e) {
throw new InputMismatchException(String.format("Invalid traffGen address pool \"%s:%s\": %s", config.getAddressPoolBase(), config.getAddressPoolPrefixLen(), e));
}
addressPool = new Inet4NetworkPool(network, 30);
}
Aggregations