MCPcopy Index your code
hub / github.com/adolfintel/NoteBot / attemptLoad

Method attemptLoad

StickyNotes/src/com/dosse/stickynotes/Main.java:161–217  ·  view source on GitHub ↗

attempts to load the notes in the specified storage. notes loaded from the file will also be adapted to the current screen DPI @param f storage @return true if loading was successful, false if it was unsuccessful (file not found or corrupt). if the storage is loaded correctly but there are no notes

(File f)

Source from the content-addressed store, hash-verified

159 * does nothing
160 */
161 private static boolean attemptLoad(File f) {
162 synchronized (notes) {
163 ObjectInputStream ois = null;
164 try {
165 ois = new ObjectInputStream(new FileInputStream(f));
166 float savScale = (Float) (ois.readObject());
167 float scaleMul = SCALE / savScale;
168 int n = (Integer) (ois.readObject());
169 if (n == 0) {
170 if (!noAutoCreate) {
171 Note note = new Note();
172 note.setVisible(true);
173 notes.add(note);
174 }
175 return true;
176 }
177 if (n < 0) {
178 return false;
179 }
180 for (int i = 0; i < n; i++) {
181 Note note = new Note();
182 Point p = (Point) (ois.readObject());
183 note.setLocation(p);
184 Dimension d = (Dimension) (ois.readObject());
185 d.height *= scaleMul;
186 d.width *= scaleMul;
187 note.setSize(d);
188 note.setColorScheme((Color[]) (ois.readObject()));
189 note.setText((String) (ois.readObject()));
190 notes.add(note);
191 }
192 try {
193 //attempt to load text scales. this will fail if we're loading a .dat file from a previous version
194 for (int i = 0; i < n; i++) {
195 notes.get(i).setTextScale((Float) (ois.readObject()));
196 }
197 } catch (Throwable t) {
198 }
199 for (Note note : notes) {
200 note.setVisible(true);
201 }
202 ois.close();
203 } catch (Throwable t) {
204 try {
205 ois.close();
206 } catch (Throwable t2) {
207 }
208 for (Note n : notes) {
209 n.setVisible(false);
210 n.dispose();
211 }
212 notes.clear();
213 return false;
214 }
215 return true;
216 }
217 }
218

Callers 1

loadStateMethod · 0.95

Calls 4

setLocationMethod · 0.95
setColorSchemeMethod · 0.95
setTextMethod · 0.95
setTextScaleMethod · 0.80

Tested by

no test coverage detected