My favorites | Sign in
Project Home Downloads Wiki Issues Source
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions

Issue 66 attachment: JadProperties.java.patch (2.9 KB)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
Index: microemu-javase/src/main/java/org/microemu/util/JadProperties.java
===================================================================
--- microemu-javase/src/main/java/org/microemu/util/JadProperties.java (revision 2413)
+++ microemu-javase/src/main/java/org/microemu/util/JadProperties.java (working copy)
@@ -26,7 +26,16 @@

package org.microemu.util;

+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
import java.util.Iterator;
+import java.util.StringTokenizer;
import java.util.Vector;
import java.util.jar.Attributes;
import java.util.jar.Manifest;
@@ -129,5 +138,68 @@
public String getProperty(String key) {
return getProperty(key, null);
}
+
+ /* (non-Javadoc)
+ * @see java.util.jar.Manifest#read(java.io.InputStream)
+ * overwritten since the manifest parser wont accept jads with spaces
+ * and newlines which is causing problems when passing in jads via
+ * commandline
+ */
+ @Override
+ public void read(InputStream is) throws IOException {
+ // TODO Auto-generated method stub
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ byte[] block = new byte[1024];
+ int bytesRead = 0;
+ while (bytesRead >= 0) {
+ bytesRead = is.read(block);
+ if (bytesRead == -1) {
+ break;
+ }
+ bos.write(block, 0, bytesRead);
+ }
+ bos.close();
+ byte[] jadBuffer = bos.toByteArray();
+ is.close();
+
+ ByteArrayInputStream bin = new ByteArrayInputStream(jadBuffer);
+ ByteArrayInputStream bin2 = new ByteArrayInputStream(jadBuffer);
+ try {
+ super.read(bin);
+ } catch (IOException e) {
+ // didnt like the format, try our own jad parser
+ readJad(bin2);
+ } finally {
+ bin.close();
+ bin2.close();
+ }
+ }

+ /**
+ * @param bin2
+ * @throws IOException
+ */
+ private void readJad(ByteArrayInputStream bin2) throws IOException {
+ BufferedReader din = null;
+ try {
+ din = new BufferedReader(new InputStreamReader(bin2));
+ String line = "";
+ while ((line = din.readLine()) != null) {
+ int pos = line.indexOf(':');
+ final String key;
+ final String value;
+ if (pos > 0) {
+ key = line.substring(0, pos).trim();
+ value = line.substring(pos + 1).trim();
+ Attributes.Name name = new Attributes.Name(key);
+ this.getMainAttributes().put(name, value);
+ }
+ }
+ } catch (IOException e) {
+
+ } finally {
+ din.close();
+ }
+ }
+
}
Powered by Google Project Hosting