Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 5ae26965

Přidáno uživatelem Michal Horký před asi 4 roky(ů)

re #7890

Tvora deamonů vyřešena přes použití ACE knihovny. Deamoni se tedy již nevytváří - knihovna se o plynulé zobrazení stará sama. Na základě zákazníkovi prosby zobrazovány i obsahy souborů bez serializovaných objektů, bylo potřeba rozšířit formátování - soubory mohou být opravdu různé, knihovna zvýrazňuje syntaxe u více jak 100 různých formátů.

Zobrazit rozdíly:

project/Deserializer/src/Converter.java
15 15

  
16 16
import jdeserialize.content;
17 17
import jdeserialize.jdeserialize;
18

  
19 18
import io.FileWorker;
20 19

  
21 20
public class Converter extends Thread {
......
27 26
	private Lock entryLock;
28 27
	private Semaphore inputAvailable;
29 28

  
29
	// Input.
30 30
	private File inputFile;
31
	private String query;
32
	private boolean testing;
33 31

  
34 32
	// Key as enum?
35 33
	private HashMap<String, String> htmlFormatting = new HashMap<String, String>();
......
44 42
	}
45 43

  
46 44
	private void fillInTestingDictionaries() {
47
		htmlFormatting.put("indent", "<span style=\"margin-left:2em\">");
45
		htmlFormatting.put("indent", "<span style=\"margin-left:2em;\">");
48 46
		htmlFormatting.put("lineBreak", "<br/>");
49
		htmlFormatting.put("classCol", "<span style=\"color:blue;font-weight:bold\">");
50
		htmlFormatting.put("fieldCol", "<span style=\"color:purple\">");
51
		htmlFormatting.put("valCol", "<span style=\"color:orange\">");
52
		htmlFormatting.put("keywordCol", "<span style=\"color:green\">");
47
		htmlFormatting.put("classCol", "<span style=\"color:blue;font-weight:bold;\">");
48
		htmlFormatting.put("fieldCol", "<span style=\"color:purple;\">");
49
		htmlFormatting.put("valCol", "<span style=\"color:orange;\">");
50
		htmlFormatting.put("keywordCol", "<span style=\"color:green;\">");
53 51
		htmlFormatting.put("closeTagCol", "</span>");
54 52

  
55 53
		jsonFormatting.put("indent", "\t");
......
63 61

  
64 62
	public void end() {
65 63
		active.set(false);
66
		setInput(null, null, false);
64
		setInput(null);
67 65
	}
68 66
	
69
	public void setInput(File inputFile, String query, boolean testing) {
67
	public void setInput(File inputFile) {
70 68
		entryLock.lock();
71 69
		this.inputFile = inputFile;
72
		this.query = query;
73
		this.testing = testing;
74 70
		entryLock.unlock();
75 71

  
76 72
		if (!inputAvailable.tryAcquire())
77 73
			inputAvailable.release(); // MAX VALUE = 1!
78 74
	}
79 75
	
80
	public boolean getInput(AtomicReference<File> inputFile, AtomicReference<String> query, AtomicBoolean testing) {
76
	public boolean getInput(AtomicReference<File> inputFile) {
81 77
		try {
82 78
			inputAvailable.acquire();
83 79
		} catch (InterruptedException e) {
......
86 82

  
87 83
		entryLock.lock();
88 84
		inputFile.set(this.inputFile);
89
		query.set(this.query);
90
		testing.set(this.testing);
91

  
85
		
92 86
		this.inputFile = null;
93
		this.query = null;
94 87
		entryLock.unlock();
95 88

  
96
		return true;
89
		return inputFile.get() != null;
97 90
	}
98 91

  
99 92
	@Override
......
101 94
		super.run();
102 95
		while (active.get()) {
103 96
			AtomicReference<File> inputFile = new AtomicReference<File>();
104
			AtomicReference<String> query = new AtomicReference<String>();
105
			AtomicBoolean testing = new AtomicBoolean();
106 97

  
107
			if (!getInput(inputFile, query, testing)) {
98
			if (!getInput(inputFile)) {
108 99
				continue;
109 100
			}
110 101

  
111
			if (inputFile.get() != null) {
112
				processA(inputFile.get(), testing.get());
113
			} else if (query.get() != null) {
114
				processB(query.get().getBytes(), testing.get());
102
			byte array[] = getBytes(inputFile.get());
103
			StringBuilder html = new StringBuilder();
104
			StringBuilder json = new StringBuilder();
105
			
106
			try {
107
				// Redirectovany system.out do null streamu. Mozno redirect do souboru
108
				System.setOut(FileWorker.createRedirectStream());
109
				convert(array, html, json);
110
			} catch (Exception e) {
111
				json.setLength(0);
112
				html.setLength(0);
113
			} finally {
114
				System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
115 115
			}
116

  
117
			//test file output
118
			try {
119
				BufferedWriter writer = new BufferedWriter(new FileWriter("html.txt"));
120
				writer.write(html.toString().replace("<br/>", "\n")); // TODO pridan replace pro odsazovani - lepsi orientace v souboru.
121
				writer.close();
122

  
123
				BufferedWriter writer2 = new BufferedWriter(new FileWriter("json.txt"));
124
				writer2.write(json.toString());
125
				writer2.close();
126
			} catch (IOException e) {
127
				// TODO Auto-generated catch block
128
				e.printStackTrace();
129
			}
130
			//test file output
131
			
132
			ui.completed(html.toString(), json.toString(), new String(array));
116 133
		}
117 134
	}
118 135

  
119
	private void processA(File input, boolean testing) {
136
	private byte[] getBytes(File input) {
120 137
		byte array[];
121 138
		try {
122 139
			array = FileWorker.loadByteArray(input);
123 140
		} catch (IOException e) {
124 141
			ui.loadingInputFileError();
125
			return;
142
			return null;
126 143
		}
127
		processB(array, testing);
144
		return array;
128 145
	}
129

  
130
	private void processB(byte array[], boolean testing) {
131
		StringBuilder html = new StringBuilder();
132
		StringBuilder json = new StringBuilder();
133

  
134
		try {
135
			// Redirectovany system.out do null streamu. Mozno redirect do souboru
136
			System.setOut(FileWorker.createRedirectStream());
137
			convert(array, html, json);
138
		} catch (Exception e) {
139
			json.setLength(0);
140
			html.setLength(0);
141
		} finally {
142
			System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
143
		}
144

  
145
		//test file output
146
		try {
147
			BufferedWriter writer = new BufferedWriter(new FileWriter("html.txt"));
148
			writer.write(html.toString());
149
			writer.close();
150

  
151
			BufferedWriter writer2 = new BufferedWriter(new FileWriter("json.txt"));
152
			writer2.write(json.toString());
153
			writer2.close();
154
		} catch (IOException e) {
155
			// TODO Auto-generated catch block
156
			e.printStackTrace();
157
		}
158
		//test file output
159

  
160
		ui.completed(html.toString(), json.toString(), testing);
161
	}
162

  
146
	
163 147
	private void convert(byte[] buffer, StringBuilder html, StringBuilder json) throws Exception {
164 148
		jdeserialize deserializer = new jdeserialize(buffer);
165 149

  

Také k dispozici: Unified diff