Projekt

Obecné

Profil

« Předchozí | Další » 

Revize a5557143

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

re #7967

Napraveny chyby až na komunikaci s DB - to je v jiném úkolu.

Zobrazit rozdíly:

project/Deserializer/src/io/FileWorker.java
25 25
public class FileWorker {
26 26
	
27 27
	private static final String CONFIG = "app.config";
28
	public static final String INPUT_DIR = "input_dir";
28 29
	public static final String ACE_MODE = "ace_mode";
29 30
	public static final String ACE_THEME = "ace_theme";
30 31
	public static final String DB_TYPE = "db_type";
......
109 110
		return new PrintStream(new File("jdeserialize_log.txt"));
110 111
	}
111 112
	
112
	public static byte[] loadByteArray(File file) throws IOException {
113
		byte fileContent[] = loadFileContent(file);
113
	public static byte[] loadFileContent(File file) throws IOException {
114
		byte buffer[] = new byte[(int) file.length()];
115
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
116
		bis.read(buffer);
117
		bis.close();
118
		return buffer;
119
	}
120
	
121
	public static byte[] unzipFile(byte content[]) throws IOException {
114 122
		byte buffer[];
115 123
		
116 124
		IZipReader input;
117 125
		try {
118
			input = new ZipInStream(new ByteArrayInputStream(fileContent));
126
			input = new ZipInStream(new ByteArrayInputStream(content));
119 127
		} catch (NoSuchElementException e) {
120 128
			System.out.println("Note: the file may be a special type of ZIP archive.");
121
			input = new InflaterInStream(new FileInputStream(file));
129
			input = new InflaterInStream(new ByteArrayInputStream(content));
122 130
		}
123 131
		
124 132
		try {
......
140 148
			System.out.println(String.format("The file is a%s ZIP archive...", input.getClass() == InflaterInStream.class ? " special" : ""));
141 149
		} catch (Exception e) {
142 150
			System.out.println("The file is not a ZIP archive...");
143
			buffer = fileContent;
151
			buffer = content;
144 152
		} finally {
145 153
			input.close();
146 154
		}
......
149 157
		return buffer;
150 158
	}
151 159

  
152
	private static byte[] loadFileContent(File file) throws IOException {
153
		byte buffer[] = new byte[(int) file.length()];
154
		BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
155
		bis.read(buffer);
156
		bis.close();
157
		return buffer;
158
	}
159
	
160 160
	public static void saveJson(File file, String json) throws IOException {
161 161
		FileWriter fw = new FileWriter(file);
162 162
		BufferedWriter bw = new BufferedWriter(fw);

Také k dispozici: Unified diff