Example usage for java.io IOException getMessage

List of usage examples for java.io IOException getMessage

Introduction

In this page you can find the example usage for java.io IOException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:com.omnigon.aem.common.utils.ParserUtil.java

/**
 *
 * @param array incoming parameters//from  w ww. j av a 2s  .c  o m
 * @param type type of Object to map
 * @param <T> -
 * @return Object with mapped parameters
 */
public static <T> ImmutableList<T> parseJsonArray(String[] array, Class<T> type) {
    final ImmutableList.Builder<T> builder = ImmutableList.builder();
    final ObjectReader reader = OBJECT_MAPPER.reader(type);
    for (String element : ArrayUtils.nullToEmpty(array)) {
        try {
            builder.add(reader.<T>readValue(element));
        } catch (IOException e) {
            LOGGER.warn(e.getMessage(), e);
        }
    }

    return builder.build();
}

From source file:Main.java

/**
 * Make a network request form ONLINE_LOCATION.
 *///from  ww  w  . j  av a  2  s .  c om
public static boolean makeNetworkCall() {
    try {
        URL url = new URL(ONLINE_LOCATION);
        HttpsURLConnection httpsURLConnection = (HttpsURLConnection) url.openConnection();
        httpsURLConnection.getInputStream();
        Log.d(TAG, "Network call completed.");
        return true;
    } catch (IOException e) {
        Log.e(TAG, "IOException " + e.getMessage());
        return false;
    }
}

From source file:Main.java

public static boolean validateXMLSchema(String xsdPath, String xmlPath) {

    try {//w w  w  .  j  a v  a 2s .c o  m
        SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
        Schema schema = factory.newSchema(new File(xsdPath));
        Validator validator = schema.newValidator();
        validator.validate(new StreamSource(new File(xmlPath)));
    } catch (IOException e) {
        System.out.println("Exception: " + e.getMessage());
        return false;
    } catch (SAXException e) {
        System.out.println("Exception: " + e.getMessage());
        return false;
    }
    return true;
}

From source file:Main.java

public static void saveToFile(File folder, String name, String data) {

    File file = new File(folder, name);

    PrintWriter pw = null;/*from w  w w . j  a  va  2 s. c o m*/
    try {
        Writer w = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
        pw = new PrintWriter(w);
        pw.write(data);

    } catch (IOException e) {
        Log.e(TAG, e.getMessage(), e);
    } finally {
        if (pw != null) {
            pw.close();
        }
    }
}

From source file:de.xwic.sandbox.base.model.util.StreamUtil.java

/**
 * @param closable/*ww  w  . j  a  va  2s  .c om*/
 * @param log
 */
public static void close(Log log, Closeable... closables) {
    for (Closeable closable : closables) {
        if (closable != null) {
            try {
                closable.close();
            } catch (IOException e) {
                log.error(e.getMessage(), e);
            }
        }
    }
}

From source file:Main.java

public static Document loadXMLFrom(InputStream inputStream) throws Exception {
    Document doc = null;/*w w  w  .  jav  a 2 s .  co  m*/
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    factory.setNamespaceAware(true);
    javax.xml.parsers.DocumentBuilder builder = null;
    try {
        builder = factory.newDocumentBuilder();
        doc = builder.parse(inputStream);
    } catch (ParserConfigurationException pce) {
        throw new Exception(pce.getMessage());
    } catch (SAXException se) {
        throw new Exception(se.getMessage());
    } catch (IOException ioe) {
        throw new Exception(ioe.getMessage());
    } finally {
        inputStream.close();
    }
    return doc;
}

From source file:Main.java

static public void CopyAsset(Context ctx, File path, String filename) throws IOException {
    AssetManager assetManager = ctx.getAssets();
    InputStream in = null;/*from   ww  w.  j  a  va  2 s . c o  m*/
    OutputStream out = null;

    // Copy files from asset folder to application folder
    try {
        in = assetManager.open(filename);
        out = new FileOutputStream(path.toString() + "/" + filename);
        copyFile(in, out);
    } catch (IOException e) {
        Log.e(TAG, e.getMessage());
        throw e;
    } finally {
        // Reclaim resources
        if (in != null) {
            in.close();
            in = null;
        }
        if (out != null) {
            out.flush();
            out.close();
            out = null;
        }
    }
}

From source file:Main.java

public static String readInStream(InputStream in) {
    try {/*from  ww  w.  j  ava2  s  . c  o  m*/
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        byte[] buffer = new byte[512];
        int length = -1;
        while ((length = in.read(buffer)) != -1) {
            out.write(buffer, 0, length);
        }
        out.close();
        in.close();
    } catch (IOException e) {
        Log.e("FileTest", e.getMessage());
    }
    return null;
}

From source file:de.neofonie.deployer.DeployerMock.java

/**
 * Read a JSON configuration from the classpath.
 *
 * @param name The filename to read from.
 * @return JsonObject with the configuration.
 *//*from w w  w . j  a  v a2s  . c  o m*/
public static JsonObject readConfiguration(final String name) {
    JsonObject result = null;
    try {
        InputStream u = DeployerVerticleTest.class.getResourceAsStream(name);
        assertNotNull(u);
        result = new JsonObject(IOUtils.toString(u));
    } catch (IOException e) {
        fail(e.getMessage());
    }
    return result;
}

From source file:edu.cuhk.hccl.SequenceFileWriter.java

private static void createSeqFile(File[] files, String seqName) {
    Configuration conf = new Configuration();
    LongWritable key = new LongWritable();
    Text value = new Text();

    SequenceFile.Writer writer = null;

    try {//from   w w  w  .  j  a  v a2 s  . co  m
        FileSystem fs = FileSystem.get(URI.create(seqName), conf);
        writer = SequenceFile.createWriter(fs, conf, new Path(seqName), key.getClass(), value.getClass());

        for (File file : files) {
            //System.out.printf("Processing file: %s \n", file.getPath());
            key.set(Integer.parseInt(file.getName().split("_")[1]));
            value.set(FileUtils.readFileToString(file));
            writer.append(key, value);
        }
        System.out.printf("[INFO] The sequence file %s has been created for %d files! \n", seqName,
                files.length);

    } catch (IOException e) {
        System.out.println(e.getMessage());
    } finally {
        IOUtils.closeStream(writer);
    }
}