Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 12-20 01:04:43.391 13298-13298/appuccino.simplyscan W/System.err﹕ java.io.StreamCorruptedException
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2068)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Util.DocumentStorageManager.getBitmapsGivenName(DocumentStorageManager.java:53)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Util.DocumentStorageManager.loadDocuments(DocumentStorageManager.java:25)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Activities.MainActivity.onCreate(MainActivity.java:108)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
- 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
- 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
- public static List<Document> loadDocuments(MainActivity main){
- List<Document> returnList = new ArrayList<>();
- main.documentNameList = PrefManager.getDocumentNames();
- //get each document given their names
- if(main.documentNameList.size() > 0) {
- for(String name : main.documentNameList) {
- List<Bitmap> bitmaps = getBitmapsGivenName(main, name);
- //TODO: handle document not found here and delete from app (bitmaps will be of size 0)
- Document doc = new Document(name, bitmaps);
- returnList.add(doc);
- }
- } else {
- return returnList;
- }
- return returnList;
- }
- private static List<Bitmap> getBitmapsGivenName(MainActivity main, String name){
- ContextWrapper cw = new ContextWrapper(main.getApplicationContext());
- // path to /data/data/yourapp/app_data/docName/
- File directory = cw.getDir(name, Context.MODE_PRIVATE);
- List<Bitmap> returnList = new ArrayList<>();
- int fileCount = 1;
- //retrieve files from directory until one isn't found
- while(true){
- MyLog.i("Trying to load Page " + fileCount + " of document " + name);
- File path = new File(directory,"Page" + fileCount + ".png");
- ObjectInputStream input;
- try {
- input = new ObjectInputStream(new FileInputStream(path));
- Bitmap bitmap = (Bitmap) input.readObject();
- returnList.add(bitmap);
- input.close();
- } catch (Exception e) {
- e.printStackTrace();
- break;
- }
- fileCount++;
- }
- return returnList;
- }
- public static void saveNewDocument(MainActivity main, Document d) {
- //add document to name list and save
- main.documentNameList.add(0, d.getName());
- PrefManager.saveDocumentNames(main.documentNameList);
- //save document's bitmaps to internal storage
- for (int i = 0; i < d.getBitmapList().size(); i++) {
- Bitmap b = d.getBitmapList().get(i);
- DocumentStorageManager.saveBitmapToInternalStorage(main, main.currentDocument.getName(), i + 1, b);
- }
- }
- private static void saveBitmapToInternalStorage(MainActivity main, String docName, int page, Bitmap compressedBitmap) {
- ContextWrapper cw = new ContextWrapper(main.getApplicationContext());
- // path to /data/data/yourapp/app_data/docName/
- File directory = cw.getDir(docName, Context.MODE_PRIVATE);
- // Create imageDir
- File path = new File(directory,"Page" + page + ".png");
- FileOutputStream fos = null;
- try {
- fos = new FileOutputStream(path);
- // Use the compress method on the BitMap object to write image to the OutputStream
- compressedBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
- fos.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- //return Uri.fromFile(path);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement