Example usage for java.io FileNotFoundException printStackTrace

List of usage examples for java.io FileNotFoundException printStackTrace

Introduction

In this page you can find the example usage for java.io FileNotFoundException printStackTrace.

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.uniteddev.Unity.Downloader.java

public static void downloadFiles() throws MalformedURLException, IOException, InterruptedException {

    class downloadFile implements Runnable {
        private int i;

        downloadFile(int i) {
            this.i = i;
        }//from w  w  w . j a  v  a2  s  .  c  om

        public void run() {
            String filename = files.get(this.i).substring(files.get(this.i).lastIndexOf('/') + 1,
                    files.get(this.i).length());
            File f = new File(Minecraft.getWorkingDirectory(), files.get(this.i));
            try {
                Login.progressText.setText("Downloading: " + filename);
                System.out.println("Downloading: " + filename);
                //System.out.println("Currently attempting Pool Index: "+this.i);
                HttpURLConnection connect_url = setupHTTP(Unity.url + Unity.folder + "/" + files.get(this.i));
                FileUtils.copyInputStreamToFile(connect_url.getInputStream(), f);
            } catch (FileNotFoundException e) {
                Login.progressText.setText("File not found!");
            } catch (MalformedURLException e) {
                System.out.println("DEV: FIX URL");
                e.printStackTrace();
            } catch (IOException e) {
                System.out.println("FileSystem Error");
                e.printStackTrace();
            }
        }
    }

    Login.progressText.setText("Downloading new files...");
    System.out.println("Downloading new files...");
    System.out.println("Number of files to download: " + files.size());
    ExecutorService pool = Executors.newFixedThreadPool(10);
    for (int i = 0; i < files.size(); i++) {
        pool.submit(new downloadFile(i));
        Login.progress.setValue((int) (((double) i / files.size()) * 100));
    }
    pool.shutdown();
    pool.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);
}

From source file:FacebookImageLoader.java

public static Bitmap loadImageFromFile(final String file, final int maxDimension, boolean exactResize) {
    // Check input
    if (file == null || file.length() == 0) {
        return null;
    }/*from  w  w  w  .  j a  va 2s.c o  m*/

    BufferedInputStream is = null;
    Bitmap image = null;

    if (exactResize) {
        // caller wants the output bitmap's max dimension scaled exactly
        // as passed in. This is slower.
        try {
            is = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
            image = BitmapFactory.decodeStream(is);
            is.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return null;
        } catch (IOException e) {
            e.printStackTrace();
            return null;
        } catch (OutOfMemoryError e) {
            // don't return, we'll try again with an inexact resize
            image = null;
        }

        if (image != null) {
            return processImageFromBitmap(image, maxDimension);
        }
    }

    // Caller does not need an exact image resize; we can achieve
    // "ballpark" using inSampleSize to save time and memory.
    BitmapFactory.Options opts = getImageSizeFromFile(file);

    if (opts == null) {
        return null;
    }

    // Calculate the resize ratio. Make the longest side
    // somewhere in the vicinity of 'maxDimension' pixels.
    int scaler = 1;
    int maxSide = Math.max(opts.outWidth, opts.outHeight);

    if (maxSide > maxDimension) {
        float ratio = (float) maxSide / (float) maxDimension;
        scaler = Math.round(ratio);
    }

    opts.inJustDecodeBounds = false;
    opts.inSampleSize = scaler;

    // This time we'll load the image for real, but with
    // inSampleSize set which will scale the image down as it is
    // loaded.
    try {
        is = new BufferedInputStream(new FileInputStream(file), BUFFER_SIZE);
        image = BitmapFactory.decodeStream(is, null, opts);
        is.close();
    } catch (FileNotFoundException e) {
        e.printStackTrace();
        return null;
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    } catch (OutOfMemoryError e) {
        e.printStackTrace();
        return null;
    }

    return image;
}

From source file:com.ibm.iotf.sample.client.gateway.devicemgmt.GatewayFirmwareHandlerSample.java

private static boolean verifyFirmware(File file, String verifier) throws IOException {
    FileInputStream fis = null;//from  w  ww. java 2 s .  c  o  m
    String md5 = null;
    try {
        fis = new FileInputStream(file);
        md5 = org.apache.commons.codec.digest.DigestUtils.md5Hex(fis);
        System.out.println("Downloaded Firmware MD5 sum:: " + md5);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        fis.close();
    }
    if (verifier.equals(md5)) {
        System.out.println("Firmware verification successful");
        return true;
    }
    System.out.println(
            "Download firmware checksum verification failed.. " + "Expected " + verifier + " found " + md5);
    return false;
}

From source file:playground.johannes.socialnets.GraphStatistics.java

public static void writeHistogramNormalized(Histogram1D hist, String filename) {
    try {/* w ww.  j  av  a2s.co m*/
        int maxBin = hist.minMaxBins()[1];
        double maxY = hist.binHeight(maxBin);

        BufferedWriter writer = IOUtils.getBufferedWriter(filename);
        writer.write("x\ty");
        writer.newLine();
        for (int i = 0; i < 100; i++) {
            writer.write(String.valueOf(hist.xAxis().binCentre(i)));
            writer.write("\t");
            writer.write(String.valueOf(hist.binHeight(i) / maxY));
            writer.newLine();
        }
        writer.close();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:com.yibu.kuaibu.app.glApplication.java

public static void saveMyBitmap(Bitmap mBitmap, String bitName) {
    File f = new File(bitName);
    Log.i("application", "" + bitName);
    FileOutputStream fOut = null;
    try {/*from  w w w  . j  a  v  a  2  s  .c o m*/
        fOut = new FileOutputStream(f);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    mBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
    try {
        fOut.flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
    try {
        fOut.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:es.tekniker.framework.ktek.commons.mng.db.CommonsLoadFile.java

public static List<String> readFile(String filename, boolean print) {
    List<String> data = new ArrayList<String>();

    BufferedReader br = null;//w ww .j a  v  a 2 s. c  om
    String line = null;
    //StringBuilder sb = new StringBuilder();
    try {

        br = new BufferedReader(new FileReader(filename));

        line = br.readLine();
        if (line != null) {
            data.add(line);
            for (String retval : line.split(";")) {
                if (print)
                    System.out.print(retval + "  ");
            }
        }
        System.out.println();
        while (line != null) {
            //sb.append(line);
            //sb.append(System.lineSeparator());
            line = br.readLine();
            if (line != null) {
                if (line.equals("") == false)
                    data.add(line);

                for (String retval : line.split(";")) {
                    if (print)
                        System.out.print(retval + "  ");
                }
                if (print)
                    System.out.println();
            }
        }
        //           String everything = sb.toString();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        log.debug("FileNotFoundException " + filename + " " + e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        log.debug("IOException " + filename + " " + e.getMessage());
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();

            log.debug("IOException closing StringBuilder " + filename + " " + e.getMessage());
        }
    }

    return data;

}

From source file:KMeansNDimension.java

private static void solutionWriter(DataSet<Tuple2<Integer, DenseVector>> res) {
    File tT = new File("/Kmeans_results.csv");
    DataOutputStream wTT = null;//from  w  ww .j  ava  2  s.c  o m
    try {
        wTT = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tT)));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    try {
        List<Tuple2<Integer, DenseVector>> tuples = res.collect();

        for (Tuple2<Integer, DenseVector> t : tuples) {
            try {
                wTT.writeChars((double) t.f0 + ","
                        + t.f1.toString().replace("DenseVector", "").replace("(", "").replace(")", "").trim()
                        + "\n");
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

        }

        wTT.close();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    //System.out.println(id+","+maxDensity+","+vector.toString());
}

From source file:finale.year.stage.utility.Util.java

public static void emptyFile() {
    //Empty the File after User Has Logged Out
    //userFile.delete();

    String response = null;/* w  w w . ja v a  2  s. c  om*/
    ObjectOutputStream writer = null;
    userFile = new File("config.txt");

    //Write to File
    try {

        writer = new ObjectOutputStream(new FileOutputStream(userFile));
        writer.writeObject(""); //Write Empty to File
        writer.writeObject(""); //Write Empty to File
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();

    } catch (IOException ex) {
        ex.printStackTrace();

    } finally {
        if (writer != null) {
            try {
                writer.close(); //Close the Reader
            } catch (IOException ex) {
                ex.printStackTrace();
                return;
            }
        }
    } //End of If Block

}

From source file:finale.year.stage.utility.Util.java

/**
 * User wishes to save credentials on current system directory
 * First time instance , provided he supplies his credentials
 * Only checking for one user at present
 * @param email/* w ww. j  av a  2s  .c o m*/
 * @param password 
 */
public static void rememberLogin(String email, String password) {
    //If user is has checked Remember me for first time
    String response = null;
    ObjectOutputStream writer = null;
    userFile = new File("config.txt");

    //Write to File
    try {

        writer = new ObjectOutputStream(new FileOutputStream(userFile));
        writer.writeObject(email); //Write Email to File
        writer.writeObject(encryptPassword(password)); //Write Password to File
        Authentification.handleResponse(login(email, encryptPassword(password)));
    } catch (FileNotFoundException ex) {
        ex.printStackTrace();

    } catch (IOException ex) {
        ex.printStackTrace();
    } catch (NoSuchAlgorithmException ex) {
        ex.printStackTrace();
    } finally {
        if (writer != null) {
            try {
                writer.close(); //Close the Reader
            } catch (IOException ex) {
                ex.printStackTrace();
                return;
            }
        }
    } //End of If Block
}

From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java

/**
 * Source:/*from  www  . j a v a2s  .  c o m*/
 * http://stackoverflow.com/questions/4349075/bitmapfactory-decoderesource
 * -returns-a-mutable-bitmap-in-android-2-2-and-an-immu
 * 
 * Converts a immutable bitmap to a mutable bitmap. This operation doesn't
 * allocates more memory that there is already allocated.
 * 
 * @param imgIn
 *            - Source image. It will be released, and should not be used
 *            more
 * @return a copy of imgIn, but immutable.
 */
public static Bitmap convertBitmapToMutable(Bitmap imgIn) {
    try {
        // this is the file going to use temporally to save the bytes.
        // This file will not be a image, it will store the raw image data.
        File file = new File(MyApp.context.getFilesDir() + File.separator + "temp.tmp");

        // Open an RandomAccessFile
        // Make sure you have added uses-permission
        // android:name="android.permission.WRITE_EXTERNAL_STORAGE"
        // into AndroidManifest.xml file
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");

        // get the width and height of the source bitmap.
        int width = imgIn.getWidth();
        int height = imgIn.getHeight();
        Config type = imgIn.getConfig();

        // Copy the byte to the file
        // Assume source bitmap loaded using options.inPreferredConfig =
        // Config.ARGB_8888;
        FileChannel channel = randomAccessFile.getChannel();
        MappedByteBuffer map = channel.map(MapMode.READ_WRITE, 0, imgIn.getRowBytes() * height);
        imgIn.copyPixelsToBuffer(map);
        // recycle the source bitmap, this will be no longer used.
        imgIn.recycle();
        System.gc();// try to force the bytes from the imgIn to be released

        // Create a new bitmap to load the bitmap again. Probably the memory
        // will be available.
        imgIn = Bitmap.createBitmap(width, height, type);
        map.position(0);
        // load it back from temporary
        imgIn.copyPixelsFromBuffer(map);
        // close the temporary file and channel , then delete that also
        channel.close();
        randomAccessFile.close();

        // delete the temporary file
        file.delete();

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return imgIn;
}