-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbinFileReader.java
161 lines (120 loc) · 4 KB
/
binFileReader.java
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
import java.io.IOException;
import java.io.*;
import java.nio.ByteBuffer;
public class binFileReader {
public static short[] Data(String file) throws IOException {
short[] Data = new short[7];
byte[] tmp = new byte[2];
InputStream InputStream = new FileInputStream(file);
InputStream.skip(5);
for(int i = 0; i < 6; i++) {
InputStream.readNBytes(tmp, 0, 2);
byte tmp2 = tmp[0];
tmp[0] = tmp[1];
tmp[1] = tmp2;
ByteBuffer buffer = ByteBuffer.allocate(2);
buffer.put(tmp);
buffer.rewind();
Data[i] = buffer.getShort();
}
InputStream.close();
return Data;
}
public static int[][] BinToInt(String file, int Columns, int Rows, int EntryX, int EntryY, int ExitX, int ExitY ) throws IOException {
int[][] Lab = new int[Columns][Rows];
byte[] counterTmp = new byte[4];
byte[] goodOrder = new byte[4];
InputStream InputStream = new FileInputStream(file);
InputStream.skip(29);
InputStream.readNBytes(counterTmp, 0, 4);
goodOrder[3]= counterTmp[0];
goodOrder[2]= counterTmp[1];
goodOrder[1]= counterTmp[2];
goodOrder[0]= counterTmp[3];
ByteBuffer buffer = ByteBuffer.allocate(4);
buffer.put(goodOrder);
buffer.rewind();
int Counter = buffer.getInt();
System.out.println("Counter " +Counter);
InputStream.skip(5);
int Wall = InputStream.read();
int Path = InputStream.read();
int index2= 0;
int index1= 0;
for(int i = 0; i < Counter; i++) {
InputStream.skip(1);
int tmp = InputStream.read();
int ile = InputStream.read();
if (tmp == Wall) {
for (int x = 0; x < ile + 1; x++) {
Lab[index1][index2] = 1;
index1++;
if(index1 == Columns)
{
index2 ++;
index1= 0;
}
}
} else {
for (int x = 0; x < ile + 1; x++) {
Lab[index1][index2] = 0;
index1++;
if(index1 == Columns)
{
index2 ++;
index1= 0;
}
}
}
}
Lab[EntryX][EntryY]= 2;
Lab[ExitX][ExitY]= 3;
InputStream.close();
return Lab;
}
/*public static void main(String[] args){
String inputFile = args[0];
short[] Data = null;
try {
Data = Data(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (int i =0 ; i < 6;i++){
System.out.print(" " +Data[i]);
}
}*/
/*public static void main(String[] args) {
String inputFile = args[0];
int[][] Lab = null;
short[] Data = null;
try {
Data = Data(inputFile);
} catch (IOException e) {
throw new RuntimeException(e);
}
int Columns = Data[0];
int Rows = Data[1];
int EnterX = Data[2];
int EnterY = Data[3];
int ExitX = Data[4];
int ExitY = Data[5];
System.out.println("Columns: " + Columns);
System.out.println("Rows: " + Rows);
System.out.println("EnterX: " + EnterX);
System.out.println("EnterY: " + EnterY);
System.out.println("ExitX: " + ExitX);
System.out.println("ExitY: " + ExitY);
try {
Lab = BinToInt(inputFile,Columns,Rows,EnterX,EnterY,ExitX,ExitY);
} catch (IOException e) {
throw new RuntimeException(e);
}
for (int i = 0; i < Rows; i++) {
for (int j = 0; j < Columns; j++) {
System.out.print(+Lab[j][i]);
}
System.out.println();
}
}*/
}