Advertisement
Guest User

Untitled

a guest
Dec 20th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.59 KB | None | 0 0
  1. 12-20 01:04:43.391 13298-13298/appuccino.simplyscan W/System.err﹕ java.io.StreamCorruptedException
  2. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2068)
  3. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at java.io.ObjectInputStream.<init>(ObjectInputStream.java:371)
  4. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Util.DocumentStorageManager.getBitmapsGivenName(DocumentStorageManager.java:53)
  5. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Util.DocumentStorageManager.loadDocuments(DocumentStorageManager.java:25)
  6. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at appuccino.simplyscan.Activities.MainActivity.onCreate(MainActivity.java:108)
  7. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933)
  8. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105)
  9. 12-20 01:04:43.396 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2251)
  10. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360)
  11. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144)
  12. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278)
  13. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102)
  14. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.os.Looper.loop(Looper.java:135)
  15. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221)
  16. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method)
  17. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372)
  18. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
  19. 12-20 01:04:43.397 13298-13298/appuccino.simplyscan W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)
  20.  
  21. public static List<Document> loadDocuments(MainActivity main){
  22. List<Document> returnList = new ArrayList<>();
  23. main.documentNameList = PrefManager.getDocumentNames();
  24. //get each document given their names
  25. if(main.documentNameList.size() > 0) {
  26. for(String name : main.documentNameList) {
  27. List<Bitmap> bitmaps = getBitmapsGivenName(main, name);
  28. //TODO: handle document not found here and delete from app (bitmaps will be of size 0)
  29.  
  30. Document doc = new Document(name, bitmaps);
  31. returnList.add(doc);
  32. }
  33. } else {
  34. return returnList;
  35. }
  36.  
  37. return returnList;
  38. }
  39.  
  40. private static List<Bitmap> getBitmapsGivenName(MainActivity main, String name){
  41. ContextWrapper cw = new ContextWrapper(main.getApplicationContext());
  42. // path to /data/data/yourapp/app_data/docName/
  43. File directory = cw.getDir(name, Context.MODE_PRIVATE);
  44.  
  45. List<Bitmap> returnList = new ArrayList<>();
  46. int fileCount = 1;
  47. //retrieve files from directory until one isn't found
  48. while(true){
  49. MyLog.i("Trying to load Page " + fileCount + " of document " + name);
  50.  
  51. File path = new File(directory,"Page" + fileCount + ".png");
  52. ObjectInputStream input;
  53.  
  54. try {
  55. input = new ObjectInputStream(new FileInputStream(path));
  56. Bitmap bitmap = (Bitmap) input.readObject();
  57. returnList.add(bitmap);
  58. input.close();
  59. } catch (Exception e) {
  60. e.printStackTrace();
  61. break;
  62. }
  63.  
  64. fileCount++;
  65. }
  66.  
  67. return returnList;
  68. }
  69.  
  70. public static void saveNewDocument(MainActivity main, Document d) {
  71. //add document to name list and save
  72. main.documentNameList.add(0, d.getName());
  73. PrefManager.saveDocumentNames(main.documentNameList);
  74.  
  75. //save document's bitmaps to internal storage
  76. for (int i = 0; i < d.getBitmapList().size(); i++) {
  77. Bitmap b = d.getBitmapList().get(i);
  78. DocumentStorageManager.saveBitmapToInternalStorage(main, main.currentDocument.getName(), i + 1, b);
  79. }
  80. }
  81.  
  82. private static void saveBitmapToInternalStorage(MainActivity main, String docName, int page, Bitmap compressedBitmap) {
  83. ContextWrapper cw = new ContextWrapper(main.getApplicationContext());
  84. // path to /data/data/yourapp/app_data/docName/
  85. File directory = cw.getDir(docName, Context.MODE_PRIVATE);
  86. // Create imageDir
  87. File path = new File(directory,"Page" + page + ".png");
  88.  
  89. FileOutputStream fos = null;
  90. try {
  91.  
  92. fos = new FileOutputStream(path);
  93.  
  94. // Use the compress method on the BitMap object to write image to the OutputStream
  95. compressedBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
  96. fos.close();
  97. } catch (Exception e) {
  98. e.printStackTrace();
  99. }
  100. //return Uri.fromFile(path);
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement