List of usage examples for java.io IOException IOException
public IOException(String message, Throwable cause)
From source file:at.uni_salzburg.cs.ckgroup.cscpp.mapper.registry.RegistryPersistence.java
@SuppressWarnings("unchecked") public static void loadRegistry(File registryFile, Map<String, IRegistrationData> registrationData) throws IOException { synchronized (lock) { String reg = FileUtils.loadFileAsString(registryFile); if (reg == null || reg.isEmpty()) { LOG.info("Can not load registry, because of empty or missing file " + registryFile); return; }/*from www. j a va 2s. c o m*/ List<Object> list; try { list = (List<Object>) parser.parse(reg); } catch (ParseException e) { throw new IOException("Parsing " + registryFile.getAbsolutePath() + " failed", e); } int counter = 0; for (Object entry : list) { RegData rd = new RegData((JSONObject) entry); registrationData.put(rd.getEngineUrl(), rd); ++counter; } LOG.info(counter + " Registry entries successfully loaded from file " + registryFile); } }
From source file:io.klerch.alexa.tellask.util.factory.AlexaSpeechletFactory.java
/** * Creates an AlexaSpeechlet from bytes of a speechlet request. It will extract the * locale from the request and uses it for creating a new instance of AlexaSpeechlet * @param serializedSpeechletRequest bytes of a speechlet request * @param speechletClass the class of your AlexaSpeechlet to instantiate * @param utteranceReader the reader AlexaSpeechlet should use when reading out utterances * @param <T> must extend AlexaSpeechlet * @return new instance of AlexaSpeechlet * @throws IOException thrown when something went wrong *//*from w w w .j av a 2 s . c om*/ public static <T extends AlexaSpeechlet> T createSpeechletFromRequest(final byte[] serializedSpeechletRequest, final Class<T> speechletClass, final UtteranceReader utteranceReader) throws IOException { final ObjectMapper mapper = new ObjectMapper(); final JsonNode parser = mapper.readTree(serializedSpeechletRequest); final String locale = Optional.of(parser.path("request")).filter(node -> !node.isMissingNode()) .map(node -> node.path("locale")).filter(node -> !node.isMissingNode()).map(JsonNode::textValue) .orElse(DEFAULT_LOCALE); try { return speechletClass.getConstructor(String.class, UtteranceReader.class).newInstance(locale, utteranceReader); } catch (InstantiationException | IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new IOException("Could not create Speechlet from speechlet request", e); } }
From source file:com.vitembp.embedded.hardware.SerialBusSensorFactory.java
/** * Builds sensor instances for serial a bus. * @param bus The bus to build sensor objects for. * @return The set of sensors connected to the bus. *///w w w . j a v a2 s. c o m static Set<Sensor> getSerialSensors(SerialBus bus) throws IOException { try { HashSet<Sensor> toReturn = new HashSet<>(); // query serial bus for sensor information bus.writeBytes(new byte[] { 'i' }); byte[] respBytes = bus.readBytes(36); String resp = new String(respBytes, Charsets.UTF_8); if (DistanceVL53L0X.TYPE_UUID.toString().equals(resp)) { toReturn.add(new DistanceVL53L0X(bus)); } else if (DistanceVL6180X.TYPE_UUID.toString().equals(resp)) { toReturn.add(new DistanceVL6180X(bus)); } else if (AccelerometerFXOS8700CQSerial.TYPE_UUID.toString().equals(resp)) { toReturn.add(new AccelerometerFXOS8700CQSerial(bus)); } else if (RotaryEncoderEAW0J.TYPE_UUID.toString().equals(resp)) { toReturn.add(new RotaryEncoderEAW0J(bus)); } else if (AccelerometerADXL326.TYPE_UUID.toString().equals(resp)) { toReturn.add(new AccelerometerADXL326(bus)); } return toReturn; } catch (IOException ex) { throw new IOException("Error enumerating bus: " + bus.getName(), ex); } }
From source file:com.cloudera.sqoop.util.DirectImportUtils.java
/** * Executes chmod on the specified file, passing in the mode string 'modstr' * which may be e.g. "a+x" or "0600", etc. * @throws IOException if chmod failed./*from w w w . jav a 2 s . c o m*/ */ public static void setFilePermissions(File file, String modstr) throws IOException { // Set this file to be 0600. Java doesn't have a built-in mechanism for this // so we need to go out to the shell to execute chmod. try { Shell.execCommand("chmod", modstr, file.toString()); } catch (IOException ioe) { // Shell.execCommand will throw IOException on exit code != 0. LOG.error("Could not chmod " + modstr + " " + file.toString()); throw new IOException("Could not ensure password file security.", ioe); } }
From source file:com.skcraft.launcher.builder.Compressor.java
public OutputStream createOutputStream(OutputStream outputStream) throws IOException { try {/*from w ww . j ava2 s .c o m*/ return factory.createCompressorOutputStream(format, outputStream); } catch (CompressorException e) { throw new IOException("Failed to create compressor", e); } }