source: java/main/src/main/java/com/framsticks/parsers/FileSource.java @ 86

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

HIGHLIGHTS:

  • use java annotations to mark classes and fields to be used when:
    • using java classes with ReflectionAccess? to represent remote objects with FramsClass? description found by "info ..." requests
    • to build up FramsClass? representation of objects not present at remote server
  • allow using primitive types (instead of wraping counterparts) in reflected classes
  • rework FramsClass? creation process (add FramsClassBuilder?)
  • add more tests

CHANGELOG:
Prepare model.World class.

Minor change.

Use primitive types for Genotype and Creature classes.

Use primitive types in model.Neuro* classes.

Use primitive types in model.Joint* classes.

Use primitive types in model.Part* classes.

Fix primitive values.

Extract FramsClassBuilder?.

Add tests of Model classes.

More fixes.

Refactorize out ParamCandidate?.

Several fixes.

Fix all regressions after introducing annotations.

Use annotations throughout the project.

Add exception classes.

Improve creation of FramsClass?.

More changes.

Many changes regarding annotations.

Annotate classes in com.framsticks.model package.

Remove manual FramsClass? constructor.

Construct FramsClass? for Creature. Add test.

Add default values to the ParamAnnotation?.

Add ParamBuilderTest? and ParamAnnotation?.

Add FramsClassAnnotation?.

File size: 1.6 KB
Line 
1package com.framsticks.parsers;
2
3import com.framsticks.params.SourceInterface;
4import com.framsticks.util.io.Encoding;
5
6import java.io.*;
7
8
9public class FileSource implements SourceInterface {
10
11        private BufferedReader reader;
12        private final String filename;
13
14        public FileSource(InputStream stream, String filename) {
15                this.filename = filename;
16                this.reader = new BufferedReader(new InputStreamReader(stream, Encoding.getFramsticksCharset()));
17        }
18
19        public FileSource(String filename) throws IOException {
20                this(new FileInputStream(filename), filename);
21        }
22
23        public FileSource(InputStream stream) {
24                this(stream, "<stream>");
25        }
26
27        @Override
28        public String readLine()
29        {
30                assert !isClosed();
31                try
32                {
33                        return reader.readLine();
34                } catch (IOException ignored) {
35
36                }
37                return null;
38        }
39
40        @Override
41        public String getFilename()
42        {
43                return filename;
44        }
45
46        @Override
47        public String demangleInclude(String include)
48        {
49                if (!include.contains(java.io.File.separator)) {
50                        String currentFilePath = (new java.io.File(filename)).getParent();
51                        if (!String.valueOf(
52                                        currentFilePath.charAt(currentFilePath.length() - 1))
53                                        .equals(java.io.File.separator)) {
54                                currentFilePath = currentFilePath + java.io.File.separator;
55                        }
56                        include = currentFilePath + include;
57                }
58                return include;
59        }
60
61        @Override
62        public SourceInterface openInclude(String include)
63        {
64                try
65                {
66                        return new FileSource(include);
67                }
68                catch(IOException e)
69                {
70
71                }
72                return null;
73        }
74
75        @Override
76        public void close()
77        {
78                try {
79                        reader.close();
80                } catch (IOException e) {
81
82                }
83                reader = null;
84        }
85
86        @Override
87        public boolean isClosed() {
88                return reader == null;
89        }
90
91}
Note: See TracBrowser for help on using the repository browser.