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:Main.java

private static void saveBitmap2TempFile(File file, Bitmap bitmap) {

    ByteArrayOutputStream bos = new ByteArrayOutputStream();
    bitmap.compress(CompressFormat.JPEG, 70 /* ignored for PNG */, bos);
    byte[] bitmapdata = bos.toByteArray();

    // write the bytes in file
    FileOutputStream fos = null;//from  w ww  .j  a v  a2  s  .  c  om
    try {

        fos = new FileOutputStream(file);

        fos.write(bitmapdata);
        fos.flush();
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {

        try {
            fos.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

}

From source file:Main.java

protected static Uri scaleDown(Uri imageUri, int targetSize, Context context) {
    System.gc();//from   w  w w .  j a  v a 2 s. c  o  m
    String imagePath = getImagePath(imageUri, context);
    Bitmap currentImage = BitmapFactory.decodeFile(imagePath);

    int targetWidth = targetSize;
    int targetHeight = targetSize;

    int width = currentImage.getWidth();
    int height = currentImage.getHeight();

    if (width < targetWidth || height < targetHeight) {
        currentImage.recycle();
        currentImage = null;
        System.gc();
        return Uri.parse(imageUri.toString());
    }

    height = (int) (height * (float) targetWidth / width);

    Bitmap scaledBitmap = Bitmap.createScaledBitmap(currentImage, targetWidth, height, false);

    if (currentImage != scaledBitmap) {
        currentImage.recycle();
        currentImage = null;
    }
    System.gc();
    File imageFile;
    try {
        imageFile = new File(context.getCacheDir(), "vumatch-upload-00.jpeg");
        FileOutputStream output;

        output = new FileOutputStream(imageFile);
        boolean result = scaledBitmap.compress(CompressFormat.JPEG, 90, output);
        if (result) {
            scaledBitmap.recycle();
            scaledBitmap = null;
            return Uri.fromFile(imageFile);
        } else {
            return null;
        }
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }

    return null;
}

From source file:Main.java

public static boolean StoreByteImage(Context mContext, byte[] imageData, int quality, String expName) {

    File sdImageMainDirectory = new File("/sdcard/myImages");
    FileOutputStream fileOutputStream = null;
    String nameFile = "";
    try {/*from w  w w  . j  a va 2s . c  om*/

        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inSampleSize = 5;

        Bitmap myImage = BitmapFactory.decodeByteArray(imageData, 0, imageData.length, options);

        fileOutputStream = new FileOutputStream(sdImageMainDirectory.toString() + "/" + nameFile + ".jpg");

        BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);

        myImage.compress(CompressFormat.JPEG, quality, bos);

        bos.flush();
        bos.close();

    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return true;
}

From source file:local.edg.ClassDB.java

/**
 * Generates a data base with class informations about a given application
 * /*ww w . j  a v a  2s .  c om*/
 * @param appClasses
 *            The classes of the application as directories to class-files or as path to jar-files.
 *            
 * @return Data base with class information.
 */
public static Map<String, Class> create(String[] appClasses) {
    ClassDbVisitor cv = new ClassDbVisitor();
    for (String s : appClasses) {
        File f = new File(s);
        if (f.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true);
            for (File cf : files) {
                try {
                    ClassReader cr = new ClassReader(new FileInputStream(cf));
                    cr.accept(cv, 0);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) {
            try {
                ZipFile zf = new ZipFile(f);
                Enumeration<? extends ZipEntry> en = zf.entries();
                while (en.hasMoreElements()) {
                    ZipEntry e = en.nextElement();
                    String name = e.getName();
                    if (name.endsWith(".class")) {
                        new ClassReader(zf.getInputStream(e)).accept(cv, 0);
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return cv.getClassDb();
}

From source file:edu.umd.cs.guitar.testcase.plugin.edg.ClassDB.java

/**
 * Generates a database containing class information about given application classes
 * @param appClasses The classes of an application as directories to class-files or as path to jar-files
 * @return Database containing class information
 *//*ww  w.  j ava 2 s. com*/
public static Map<String, Class> create(String[] appClasses) {
    ClassDBVisitor cv = new ClassDBVisitor();
    for (String s : appClasses) {
        File f = new File(s);
        if (f.isDirectory()) {
            Collection<File> files = FileUtils.listFiles(f, new String[] { "class" }, true);
            for (File cf : files) {
                try {
                    ClassReader cr = new ClassReader(new FileInputStream(cf));
                    cr.accept(cv, 0);
                } catch (FileNotFoundException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        } else if (f.isFile() && s.toLowerCase().endsWith(".jar")) {
            try {
                ZipFile zf = new ZipFile(f);
                Enumeration<? extends ZipEntry> en = zf.entries();
                while (en.hasMoreElements()) {
                    ZipEntry e = en.nextElement();
                    String name = e.getName();
                    if (name.endsWith(".class")) {
                        new ClassReader(zf.getInputStream(e)).accept(cv, 0);
                    }
                }
            } catch (IOException e1) {
                e1.printStackTrace();
            }
        }
    }
    return cv.getClassDb();
}

From source file:com.carteblanche.kwd.parsers.TestCaseParser.java

public static KWDTestCase parse(File csv, String cvsSplitBy) {

    BufferedReader br = null;/*w  w w  .j a  va2 s .com*/
    String line = "";
    String csvFile = csv.getAbsolutePath();

    try {

        File file = new File(csvFile);

        String testCaseName = file.getName();
        testCaseName = testCaseName.replace(".csv", "");
        testCaseName = StringUtils
                .capitalize(StringUtils.join(StringUtils.splitByCharacterTypeCamelCase(testCaseName), ' '));
        br = new BufferedReader(new FileReader(csvFile));
        ArrayList<KWDTestMethod> testMethods = new ArrayList<KWDTestMethod>();
        while ((line = br.readLine()) != null) {

            // use comma as separator
            String[] columns = line.split(cvsSplitBy);

            if (columns.length < 1) {
                System.out.println("Every row should have atleast 1 Column");
                System.exit(122);
            }

            ArrayList<String> parameters = new ArrayList<String>();
            for (int i = 1; i < columns.length; i++) {
                parameters.add(columns[i]);
            }
            KWDTestMethod testMethod = new KWDTestMethod(columns[0], parameters);
            testMethod.setClasssName("com.carteblanche.kwd.tests.Login");
            testMethods.add(testMethod);
        }
        KWDTestCase testCase = new KWDTestCase(testCaseName, testMethods);
        return testCase;
        // return new KWDTestSuite(testSuiteName, testcases);
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (br != null) {
            try {
                br.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    return null;
}

From source file:Main.java

/**
 * Loads an XML document from a File/*from  www.j  av a2 s  .c  o  m*/
 * @param uri The path the file.
 */
public static Document loadXmlDoc(final String uri) {
    Document result = null;
    try {
        File file = new File(uri);
        if (file.exists()) {
            result = loadXmlDoc(new FileInputStream(file));

        } else {
            throw new IOException("File does not exist: " + file.getAbsolutePath());
        }
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    return result;
}

From source file:Main.java

/**
 * Stores a {@code org.w3c.dom.Document} to a local File.
 * //w ww.j  a v a2 s.c  o  m
 * Code segments from {@url http://www.exampledepot.com/egs/org.w3c.dom/RemNode.html}
 * @param f the file
 * @param dom the document
 * 
 */
public static void storeDocumentToFile(Document dom, File f) {
    OutputFormat format = new OutputFormat(dom);
    XMLSerializer output;
    try {
        output = new XMLSerializer(new FileOutputStream(f), format);
        output.serialize(dom);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

}

From source file:Main.java

public static String savePicture(Bitmap bmp, String file) {
    File filepicture = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    if (file == null || file.equals("")) {
        file = filepicture + "/" + System.currentTimeMillis() + ".jpg";
    }//from   w w w  .ja v  a 2 s. c om
    FileOutputStream outputStream = null;
    try {
        outputStream = new FileOutputStream(file);
        bmp.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            return "";
        }
    } finally {
        if (outputStream != null) {
            try {
                outputStream.flush();
                outputStream.close();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
        }
    }
    return "file://" + file;
}

From source file:Main.java

public static void copyFileUsingStream(String sourcePath, String destPath) {
    File source = new File(sourcePath);
    File dest = new File(destPath);
    InputStream is = null;//from   w ww  . j a  v  a 2  s.c  om
    OutputStream os = null;
    try {
        try {
            is = new FileInputStream(source);
            os = new FileOutputStream(dest);
            byte[] buffer = new byte[1024];
            int length;
            while ((length = is.read(buffer)) > 0) {
                os.write(buffer, 0, length);
            }
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } finally {
        try {
            is.close();
            os.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }
}