source: java/main/src/main/java/com/framsticks/dumping/FileInstance.java @ 85

Last change on this file since 85 was 85, checked in by psniegowski, 11 years ago

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File size: 1.5 KB
Line 
1package com.framsticks.dumping;
2
3import com.framsticks.core.LocalInstance;
4import com.framsticks.core.Path;
5import com.framsticks.core.Instance;
6import com.framsticks.util.dispatching.Future;
7import com.framsticks.util.io.Encoding;
8
9import org.apache.commons.configuration.Configuration;
10import org.apache.log4j.Logger;
11
12import java.io.BufferedReader;
13import java.io.File;
14import java.io.FileInputStream;
15import java.io.IOException;
16import java.io.InputStreamReader;
17
18/**
19 * @author Piotr Sniegowski
20 */
21public class FileInstance extends LocalInstance {
22
23        private static final Logger log = Logger.getLogger(Instance.class.getName());
24        protected File file;
25
26        public FileInstance() {
27        }
28
29        @Override
30        public void configure(Configuration config) {
31                super.configure(config);
32                file = new File(config.getString("filename"));
33        }
34
35        @Override
36        public void run() {
37                assert isActive();
38                super.run();
39                try {
40                        LoadStream stream = new LoadStream(this.getRootPath(), new BufferedReader(new InputStreamReader(new FileInputStream(file), Encoding.getFramsticksCharset())), this, new Future<Path>() {
41                                @Override
42                                public void result(Path result, Exception e) {
43                                        if (e != null) {
44                                                log.error("failed to load file instance " + FileInstance.this + ": " + e);
45                                                fireRun(e);
46                                                return;
47                                        }
48                                        log.info("loaded file instance " + FileInstance.this);
49                                        fireRun(null);
50                                }
51                        });
52                        stream.load();
53                } catch (IOException e) {
54                        log.error("io failure: " + e);
55                        fireRun(e);
56                }
57        }
58
59        @Override
60        public String toString() {
61                return "file@" + file.getName();
62        }
63
64
65
66}
Note: See TracBrowser for help on using the repository browser.