Example usage for java.io IOException getCause

List of usage examples for java.io IOException getCause

Introduction

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

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java

/**
 * This will initialize the JPA Entity Manager Factory. This will determine if
 * the database connection settings are correct.
 * // w w w.  j a  v a 2s  .  c o  m
 * @throws ServletException
 */
private static void initializeEntityFactory() throws ServletException {
    logger.info("intializing Persistence Entity Factory");
    //
    // Pull custom persistence settings
    //
    Properties properties;
    try {
        properties = XACMLProperties.getProperties();
    } catch (IOException e) {
        throw new ServletException(e.getMessage(), e.getCause());
    }
    //
    // Create the factory
    //
    emf = Persistence.createEntityManagerFactory(XacmlAdminUI.PERSISTENCE_UNIT, properties);
    //
    // Did it get created?
    //
    if (emf == null) {
        throw new ServletException("Unable to create Entity Manager Factory");
    }
    //
    // Create our JDBC connection pool
    //
    try {
        logger.info("intializing JDBC Connection Pool");
        XacmlAdminUI.pool = new XacmlJDBCConnectionPool(
                properties.getProperty(PersistenceUnitProperties.JDBC_DRIVER),
                properties.getProperty(PersistenceUnitProperties.JDBC_URL),
                properties.getProperty(PersistenceUnitProperties.JDBC_USER),
                properties.getProperty(PersistenceUnitProperties.JDBC_PASSWORD));
    } catch (SQLException e) {
        throw new ServletException(e.getMessage(), e.getCause());
    }
}

From source file:org.efaps.update.version.Application.java

/**
 * <code>null</code> is returned, of the version file could not be opened
 * and read./* w  w  w.j ava  2  s .c o m*/
 *
 * @param _versionUrl URL of the version file which defines the application
 * @param _rootUrl root URL where the source files are located (for local
 *            files); URL of the class file (if source is in a Jar file)
 * @param _classpathElements elements of the class path
 * @return application instance with all version information
 * @throws InstallationException if version XML file could not be parsed
 */
public static Application getApplication(final URL _versionUrl, final URL _rootUrl,
        final List<String> _classpathElements) throws InstallationException {
    Application appl = null;
    try {
        final DigesterLoader loader = DigesterLoader.newLoader(new FromAnnotationsRuleModule() {
            @Override
            protected void configureRules() {
                bindRulesFrom(Application.class);
            }
        });
        final Digester digester = loader.newDigester();
        appl = (Application) digester.parse(_versionUrl);
        appl.rootUrl = _rootUrl;
        appl.classpathElements = _classpathElements;
        for (final InstallFile installFile : appl.tmpElements) {
            appl.install.addFile(installFile.setURL(new URL(_rootUrl, installFile.getName())));
        }
        appl.tmpElements = null;
        Collections.sort(appl.dependencies, new Comparator<Dependency>() {

            @Override
            public int compare(final Dependency _dependency0, final Dependency _dependency1) {
                return _dependency0.getOrder().compareTo(_dependency1.getOrder());
            }
        });
        for (final ApplicationVersion applVers : appl.getVersions()) {
            applVers.setApplication(appl);
            appl.setMaxVersion(applVers.getNumber());
        }

    } catch (final IOException e) {
        if (e.getCause() instanceof InstallationException) {
            throw (InstallationException) e.getCause();
        } else {
            throw new InstallationException("Could not open / read version file '" + _versionUrl + "'");
        }
        //CHECKSTYLE:OFF
    } catch (final Exception e) {
        //CHECKSTYLE:ON
        throw new InstallationException("Error while parsing file '" + _versionUrl + "'", e);
    }
    return appl;
}

From source file:mas.MAS.java

public static String getData2(String url_org, int start) {

    try {/*w  ww.  j a  v a 2 s.c o  m*/
        String complete_url = url_org + "&$skip=" + start;
        //            String url_str = generateURL(url_org, prop);
        Document doc = Jsoup.connect(complete_url).timeout(25000).ignoreContentType(true).get();
        return doc.text();
    } catch (IOException ex) {
        System.out.println(ex.getMessage() + " Cause: " + ex.getCause());
        Logger.getLogger(MAS.class.getName()).log(Level.SEVERE, null, ex);
    }
    return null;
}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public static ArrayList<String> loadStringData(InputStream stream) {
    ArrayList<String> mlist = new ArrayList<String>(150);
    int line = 0;

    try {//from   w w  w.j  a v  a 2  s. c  om
        InputStreamReader is = new InputStreamReader(stream);
        BufferedReader in = new BufferedReader(is);
        CSVReader csv = new CSVReader(in, ';', '\"', 0);
        String data[];

        while ((data = csv.readNext()) != null) {
            line++;
            mlist.add(data[1]);
        }

        in.close();

    } catch (IOException ioe) {
        Log.e("Read CSV Error mypapit", "Some CSV Error: ", ioe.getCause());

    } catch (NumberFormatException nfe) {
        Log.e("Number error", "parse number error - line: " + line + "  " + nfe.getMessage(), nfe.getCause());
    } catch (Exception ex) {
        Log.e("Some Exception", "some exception at line :" + line + " \n " + ex.getCause());
        ex.printStackTrace(System.err);
    }
    // Collections.sort(mlist);

    return mlist;

}

From source file:net.mypapit.mobile.myrepeater.RepeaterListActivity.java

public static RepeaterList loadData(int resource, Activity activity) {
    RepeaterList mlist = new RepeaterList(150);
    int line = 0;
    try {//from ww w.j av a 2  s .  c  o  m

        InputStreamReader is = new InputStreamReader(activity.getResources().openRawResource(resource));
        BufferedReader in = new BufferedReader(is);
        CSVReader csv = new CSVReader(in, ';', '\"', 0);
        String data[];

        while ((data = csv.readNext()) != null) {
            line++;
            mlist.add(new Repeater("", data[1], data[2], data[3], data[9], Double.parseDouble(data[4]),
                    Double.parseDouble(data[5]), Double.parseDouble(data[6]), Double.parseDouble(data[7]),
                    Double.parseDouble(data[8])));

        }

        in.close();

    } catch (IOException ioe) {
        Log.e("Read CSV Error mypapit", "Some CSV Error: ", ioe.getCause());

    } catch (NumberFormatException nfe) {
        Log.e("Number error", "parse number error - line: " + line + "  " + nfe.getMessage(), nfe.getCause());
    } catch (Exception ex) {
        Log.e("Some Exception", "some exception at line :" + line + " \n " + ex.getCause());
        ex.printStackTrace(System.err);
    }

    return mlist;

}

From source file:com.bitranger.parknshop.util.ObjUtils.java

public static byte[] toBytes(Object obj) {

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream objOut = null;
    byte[] plainObj = null;

    try {//from www  . j  ava2  s.  c o m
        objOut = new ObjectOutputStream(baos);
        objOut.writeObject(obj);
        plainObj = baos.toByteArray();
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage() + "\n\tCAUSE: " + e.getCause(), e);
    } finally {
        try {
            baos.close();
            if (objOut != null) {
                objOut.close();
            }
        } catch (IOException e) {
            throw new RuntimeException(e.getMessage() + "\n\tCAUSE: " + e.getCause(), e);
        }
    }
    return plainObj;
}

From source file:org.apache.openaz.xacml.admin.XacmlAdminUI.java

private static void initializeGitRepository() throws ServletException {
    XacmlAdminUI.repositoryPath = Paths
            .get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_REPOSITORY));
    FileRepositoryBuilder builder = new FileRepositoryBuilder();
    try {//from   w  w w.  ja v  a  2 s.  c  o  m
        XacmlAdminUI.repository = builder.setGitDir(XacmlAdminUI.repositoryPath.toFile()).readEnvironment()
                .findGitDir().setBare().build();
        if (Files.notExists(XacmlAdminUI.repositoryPath)
                || Files.notExists(Paths.get(XacmlAdminUI.repositoryPath.toString(), "HEAD"))) {
            //
            // Create it if it doesn't exist. As a bare repository
            //
            logger.info("Creating bare git repository: " + XacmlAdminUI.repositoryPath.toString());
            XacmlAdminUI.repository.create();
            //
            // Add the magic file so remote works.
            //
            Path daemon = Paths.get(XacmlAdminUI.repositoryPath.toString(), "git-daemon-export-ok");
            Files.createFile(daemon);
        }
    } catch (IOException e) {
        logger.error("Failed to build repository: " + repository, e);
        throw new ServletException(e.getMessage(), e.getCause());
    }
    //
    // Make sure the workspace directory is created
    //
    Path workspace = Paths.get(XACMLProperties.getProperty(XACMLRestProperties.PROP_ADMIN_WORKSPACE));
    workspace = workspace.toAbsolutePath();
    if (Files.notExists(workspace)) {
        try {
            Files.createDirectory(workspace);
        } catch (IOException e) {
            logger.error("Failed to build workspace: " + workspace, e);
            throw new ServletException(e.getMessage(), e.getCause());
        }
    }
    //
    // Create the user workspace directory
    //
    workspace = Paths.get(workspace.toString(), "pe");
    if (Files.notExists(workspace)) {
        try {
            Files.createDirectory(workspace);
        } catch (IOException e) {
            logger.error("Failed to create directory: " + workspace, e);
            throw new ServletException(e.getMessage(), e.getCause());
        }
    }
    //
    // Get the path to where the repository is going to be
    //
    Path gitPath = Paths.get(workspace.toString(), XacmlAdminUI.repositoryPath.getFileName().toString());
    if (Files.notExists(gitPath)) {
        try {
            Files.createDirectory(gitPath);
        } catch (IOException e) {
            logger.error("Failed to create directory: " + gitPath, e);
            throw new ServletException(e.getMessage(), e.getCause());
        }
    }
    //
    // Initialize the domain structure
    //
    String base = null;
    String domain = XacmlAdminUI.getDomain();
    if (domain != null) {
        for (String part : Splitter.on(':').trimResults().split(domain)) {
            if (base == null) {
                base = part;
            }
            Path subdir = Paths.get(gitPath.toString(), part);
            if (Files.notExists(subdir)) {
                try {
                    Files.createDirectory(subdir);
                    Files.createFile(Paths.get(subdir.toString(), ".svnignore"));
                } catch (IOException e) {
                    logger.error("Failed to create: " + subdir, e);
                    throw new ServletException(e.getMessage(), e.getCause());
                }
            }
        }
    } else {
        try {
            Files.createFile(Paths.get(workspace.toString(), ".svnignore"));
            base = ".svnignore";
        } catch (IOException e) {
            logger.error("Failed to create file", e);
            throw new ServletException(e.getMessage(), e.getCause());
        }
    }
    try {
        //
        // These are the sequence of commands that must be done initially to
        // finish setting up the remote bare repository.
        //
        Git git = Git.init().setDirectory(gitPath.toFile()).setBare(false).call();
        git.add().addFilepattern(base).call();
        git.commit().setMessage("Initialize Bare Repository").call();
        StoredConfig config = git.getRepository().getConfig();
        config.setString("remote", "origin", "url", XacmlAdminUI.repositoryPath.toAbsolutePath().toString());
        config.setString("remote", "origin", "fetch", "+refs/heads/*:refs/remotes/origin/*");
        config.save();
        git.push().setRemote("origin").add("master").call();
        /*
         * This will not work unless git.push().setRemote("origin").add("master").call();
         * is called first. Otherwise it throws an exception. However, if the push() is
         * called then calling this function seems to add nothing.
         * 
        git.branchCreate().setName("master")
           .setUpstreamMode(SetupUpstreamMode.SET_UPSTREAM)
           .setStartPoint("origin/master").setForce(true).call();
        */
    } catch (GitAPIException | IOException e) {
        logger.error(e);
        throw new ServletException(e.getMessage(), e.getCause());
    }
}

From source file:org.nuxeo.opensocial.webengine.gadgets.GadgetStreamWriter.java

public void writeTo(GadgetStream t, Class<?> type, Type genericType, Annotation[] annotations,
        MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
        throws IOException, WebApplicationException {
    try {//from   ww  w  .  j  a  v  a  2 s.com
        FileUtils.copy(t.getStream(), entityStream);
    } catch (IOException e) {
        Throwable cause = e.getCause();
        if (cause != null && "Broken pipe".equals(cause.getMessage())) {
            log.debug("Swallowing: " + e);
        } else {
            throw e;
        }
    } finally {
        t.getStream().close();
    }
}

From source file:org.mule.transport.ftp.FtpMuleMessageFactoryStreamlessFailureTestCase.java

private void assertExceptionAndCause(Throwable t) throws Exception {
    try {// w  w w. jav a 2  s  . c  o  m
        factory.extractPayload(file, ENCODING);
        fail("was expecting failure");
    } catch (IOException e) {
        assertThat(e.getCause(), is(t));
    }
}

From source file:net.yoomai.virgo.spider.parsers.ICISParser.java

@Override
public List<Estimate> parser(File htmlFile) {
    Document doc = null;//from   w  w w  . j  a va 2 s.  c om
    try {
        doc = Jsoup.parse(htmlFile, "UTF-8");
    } catch (IOException e) {
        log.error(e.getMessage() + " : " + e.getCause());
    }

    log.info("doc: " + doc);
    if (doc != null) {
        Elements elements = doc.getElementsByClass("price-datalist");
        for (int i = 0; i < elements.size(); i++) {
            Element element = elements.get(i);
            log.info(element.toString());
        }
    }

    return null;
}