Example usage for java.io IOException toString

List of usage examples for java.io IOException toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.wso2.cdm.agent.proxy.ServerApiAccess.java

public static String getResponseBody(HttpResponse response) {

    String response_text = null;/*from  w  w w. j a v a2  s.  c  o  m*/
    HttpEntity entity = null;
    try {
        entity = response.getEntity();
        response_text = getResponseBodyContent(entity);
    } catch (ParseException e) {
        Log.d(TAG, e.toString());
    } catch (IOException e) {
        if (entity != null) {
            try {
                entity.consumeContent();
            } catch (IOException e1) {
                Log.d(TAG, e1.toString());
            }
        }
    }
    return response_text;
}

From source file:com.example.shutapp.DatabaseHandler.java

private static boolean downloadDatabase(Context context) {
    try {//from   www. j  a v  a2s . co  m
        Log.d(TAG, "downloading database");
        URL url = new URL(StringLiterals.SERVER_DB_URL);
        /* Open a connection to that URL. */
        URLConnection ucon = url.openConnection();
        /*
         * Define InputStreams to read from the URLConnection.
         */
        InputStream is = ucon.getInputStream();
        BufferedInputStream bis = new BufferedInputStream(is);
        /*
         * Read bytes to the Buffer until there is nothing more to read(-1).
         */
        ByteArrayBuffer baf = new ByteArrayBuffer(StringLiterals.DATABASE_BUFFER);
        int current = 0;
        while ((current = bis.read()) != -1) {
            baf.append((byte) current);
        }

        /* Convert the Bytes read to a String. */
        FileOutputStream fos = null;
        // Select storage location
        fos = context.openFileOutput("db_name.s3db", Context.MODE_PRIVATE);

        fos.write(baf.toByteArray());
        fos.close();
        Log.d(TAG, "downloaded");
    } catch (IOException e) {
        String exception = e.toString();
        Log.e(TAG, "downloadDatabase Error: " + exception);
        return false;
    } catch (Exception e) {
        String exception = e.toString();
        Log.e(TAG, "downloadDatabase Error: " + exception);
        return false;
    }
    return true;
}

From source file:com.ushahidi.android.app.util.ApiUtils.java

/**
 * Check if an ushahidi deployment has changed it's HTTP protocol to HTTPS
 * or not. Then update if it has./*from www .ja v a2 s  .  c o m*/
 * 
 * @param context - the calling activity.
 */
public static void updateDomain(Context context) {

    Preferences.loadSettings(context);

    StringBuilder uriBuilder = new StringBuilder(Preferences.domain);
    uriBuilder.append("/api?task=version");
    uriBuilder.append("&resp=json");

    try {
        response = MainHttpClient.GetURL(uriBuilder.toString());
        if (response != null) {

            final int statusCode = response.getStatusLine().getStatusCode();

            if (statusCode == 200) {

                jsonString = MainHttpClient.GetText(response);
                JSONObject jsonObject = new JSONObject(jsonString);
                String changedDomain = jsonObject.getJSONObject("payload").getString("domain");

                Preferences.domain = changedDomain;

                // save changes
                Preferences.saveSettings(context);

            }
        }

    } catch (IOException e) {
        Log.e(CLASS_TAG, e.toString());
    } catch (JSONException e) {
        Log.e(CLASS_TAG, e.toString());
    }
}

From source file:org.jetbrains.webdemo.examples.ExamplesLoader.java

private static Example loadExample(String path, String parentUrl, boolean loadTestVersion,
        List<ObjectNode> commonFilesManifests) throws IOException {
    File manifestFile = new File(path + File.separator + "manifest.json");
    try (BufferedInputStream reader = new BufferedInputStream(new FileInputStream(manifestFile))) {
        ObjectNode manifest = (ObjectNode) JsonUtils.getObjectMapper().readTree(reader);

        String name = new File(path).getName();
        String id = (parentUrl + name).replaceAll(" ", "%20");
        String args = manifest.has("args") ? manifest.get("args").asText() : "";
        String runConfiguration = manifest.get("confType").asText();
        boolean searchForMain = manifest.has("searchForMain") ? manifest.get("searchForMain").asBoolean()
                : true;/*w  w  w .ja va 2  s . c  o  m*/
        String expectedOutput;
        List<String> readOnlyFileNames = new ArrayList<>();
        List<ProjectFile> files = new ArrayList<>();
        List<ProjectFile> hiddenFiles = new ArrayList<>();
        if (manifest.has("expectedOutput")) {
            expectedOutput = manifest.get("expectedOutput").asText();
        } else if (manifest.has("expectedOutputFile")) {
            Path expectedOutputFilePath = Paths
                    .get(path + File.separator + manifest.get("expectedOutputFile").asText());
            expectedOutput = new String(Files.readAllBytes(expectedOutputFilePath));
        } else {
            expectedOutput = null;
        }
        String help = null;
        File helpFile = new File(path + File.separator + "task.md");
        if (helpFile.exists()) {
            PegDownProcessor processor = new PegDownProcessor(org.pegdown.Extensions.FENCED_CODE_BLOCKS);
            String helpInMarkdown = new String(Files.readAllBytes(helpFile.toPath()));
            help = new GFMNodeSerializer().toHtml(processor.parseMarkdown(helpInMarkdown.toCharArray()));
        }

        List<JsonNode> fileManifests = new ArrayList<JsonNode>();
        if (manifest.has("files")) {
            for (JsonNode fileManifest : manifest.get("files")) {
                fileManifests.add(fileManifest);
            }
        }
        fileManifests.addAll(commonFilesManifests);
        for (JsonNode fileDescriptor : fileManifests) {

            if (loadTestVersion && fileDescriptor.has("skipInTestVersion")
                    && fileDescriptor.get("skipInTestVersion").asBoolean()) {
                continue;
            }

            String filePath = fileDescriptor.has("path") ? fileDescriptor.get("path").asText()
                    : path + File.separator + fileDescriptor.get("filename").textValue();
            ExampleFile file = loadExampleFile(filePath, id, fileDescriptor);
            if (!loadTestVersion && file.getType().equals(ProjectFile.Type.SOLUTION_FILE)) {
                continue;
            }
            if (!file.isModifiable()) {
                readOnlyFileNames.add(file.getName());
            }

            if (file.isHidden()) {
                hiddenFiles.add(file);
            } else {
                files.add(file);
            }
        }
        loadDefaultFiles(path, id, files, loadTestVersion);

        return new Example(id, name, args, runConfiguration, id, expectedOutput, searchForMain, files,
                hiddenFiles, readOnlyFileNames, help);
    } catch (IOException e) {
        System.err.println("Can't load project: " + e.toString());
        return null;
    }
}

From source file:com.example.healthplus.wifidirect.DeviceDetailFragment.java

public static boolean copyFile(InputStream inputStream, OutputStream out) {
    byte buf[] = new byte[1024];
    int len;/*from  w  w  w  .  j  a v a2s.  c o m*/
    try {
        while ((len = inputStream.read(buf)) != -1) {
            //System.out.println("len =inputStream"+);
            out.write(buf, 0, len);

        }
        out.close();
        inputStream.close();
    } catch (IOException e) {
        Log.d(WiFiDirectActivity.TAG, e.toString());
        return false;
    }
    return true;
}

From source file:com.panet.imeta.core.vfs.KettleVFS.java

public static FileObject getFileObject(String vfsFilename) throws IOException {
    checkHook();// w  ww  . ja  v  a  2  s.  c o  m

    try {
        FileSystemManager fsManager = VFS.getManager();

        // We have one problem with VFS: if the file is in a subdirectory of the current one: somedir/somefile
        // In that case, VFS doesn't parse the file correctly.
        // We need to put file: in front of it to make it work.
        // However, how are we going to verify this?
        // 
        // We are going to see if the filename starts with one of the known protocols like file: zip: ram: smb: jar: etc.
        // If not, we are going to assume it's a file.
        //
        boolean relativeFilename = true;
        String[] schemes = VFS.getManager().getSchemes();
        for (int i = 0; i < schemes.length && relativeFilename; i++) {
            if (vfsFilename.startsWith(schemes[i] + ":"))
                relativeFilename = false;
        }

        String filename;
        if (vfsFilename.startsWith("\\\\")) {
            File file = new File(vfsFilename);
            filename = file.toURI().toString();
        } else {
            if (relativeFilename) {
                File file = new File(vfsFilename);
                filename = file.getAbsolutePath();
            } else {
                filename = vfsFilename;
            }
        }

        FileObject fileObject = fsManager.resolveFile(filename);

        return fileObject;
    } catch (IOException e) {
        throw new IOException(
                "Unable to get VFS File object for filename '" + vfsFilename + "' : " + e.toString());
    }
}

From source file:com.intuit.tank.harness.AmazonUtil.java

/**
 * //from  w  w w.  ja va 2 s  . c o m
 * @return
 */
public static String getAWSKeyFromUserData() {
    String ret = null;
    try {
        ret = getUserDataAsMap().get(TankConstants.KEY_AWS_SECRET_KEY);
    } catch (IOException e) {
        LOG.warn("Error getting key: " + e.toString());
    }
    return ret;
}

From source file:com.intuit.tank.harness.AmazonUtil.java

/**
 * /*w  w w.  ja  va  2  s .com*/
 * @return
 */
public static String getAWSKeyIdFromUserData() {
    String ret = null;
    try {
        ret = getUserDataAsMap().get(TankConstants.KEY_AWS_SECRET_KEY_ID);
    } catch (IOException e) {
        LOG.warn("Error getting key ID: " + e.toString());
    }
    return ret;
}

From source file:com.intuit.tank.harness.AmazonUtil.java

/**
 * gets the job id form user data/*w ww . ja  va2 s  .c  om*/
 * 
 * @return
 */
public static String getJobId() {
    String ret = null;
    try {
        ret = getUserDataAsMap().get(TankConstants.KEY_JOB_ID);
    } catch (IOException e) {
        LOG.warn("Error getting job ID: " + e.toString());
    }
    return ret != null ? ret : "unknown";
}

From source file:com.intuit.tank.harness.AmazonUtil.java

/**
 * Attempts to get the amazon instance-id of the current VM.
 * //from w w w .ja  va2 s.  c om
 * @return the instance Id or null
 */
@Nonnull
public static String getInstanceId() {
    String ret = null;
    try {
        ret = getMetaData(CloudMetaDataType.instance_id);
    } catch (IOException e) {
        LOG.warn("Error getting instance ID: " + e.toString());
    }
    return ret;
}