saves currently open notes to the main storage, and turns the previous storage to the backup storage. FORMAT: The .dat file will hold data as serialized objects. A Float contains the SCALE at which the save was made, then an Integer contains the number of notes, then for each note we have its locat
()
| 104 | * errors are ignored. |
| 105 | */ |
| 106 | public static void saveState() { |
| 107 | synchronized (notes) { |
| 108 | ObjectOutputStream oos = null; |
| 109 | try { |
| 110 | File st = new File(STORAGE_PATH); |
| 111 | File bk = new File(BACKUP_PATH); |
| 112 | File bkTemp = new File(BACKUP2_PATH); |
| 113 | if (bkTemp.exists()) { |
| 114 | bkTemp.delete(); |
| 115 | } |
| 116 | if (bk.exists()) { |
| 117 | bk.renameTo(bkTemp); |
| 118 | } |
| 119 | if (st.exists()) { |
| 120 | st.renameTo(bk); |
| 121 | } |
| 122 | if (bkTemp.exists()) { |
| 123 | bkTemp.delete(); |
| 124 | } |
| 125 | st = new File(STORAGE_PATH); |
| 126 | oos = new ObjectOutputStream(new FileOutputStream(st)); |
| 127 | oos.writeObject(SCALE); |
| 128 | oos.writeObject(notes.size()); |
| 129 | for (Note n : notes) { |
| 130 | oos.writeObject(n.getPreferredLocation()); |
| 131 | oos.writeObject(n.getSize()); |
| 132 | oos.writeObject(n.getColorScheme()); |
| 133 | oos.writeObject(n.getText()); |
| 134 | } |
| 135 | //text scales are written at the end of the file so that older versions of the program can still load this .dat file |
| 136 | for (Note n : notes) { |
| 137 | oos.writeObject(n.getTextScale()); |
| 138 | } |
| 139 | oos.flush(); |
| 140 | oos.close(); |
| 141 | } catch (Throwable t) { |
| 142 | try { |
| 143 | oos.close(); |
| 144 | } catch (Throwable t2) { |
| 145 | } |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /** |
| 151 | * attempts to load the notes in the specified storage. notes loaded from |
no test coverage detected