Skip to content

Commit 80b7a6c

Browse files
authored
Merge pull request #30 from EmbroidePy/0.1.22
Correct HusReader, java9 function
2 parents 34c047c + c4194b7 commit 80b7a6c

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

core/src/main/java/org/embroideryio/embroideryio/EmbCompress.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ public ByteBuffer decompress(ByteBuffer input_data_set, int uncompressed_size) {
197197
ByteBuffer output_data = ByteBuffer.allocate(uncompressed_size);
198198
block_elements = -1;
199199
int bits_total = input_data.array().length * 8;
200-
while ((bits_total > bit_position) && ((uncompressed_size == -1) || (output_data.array().length <= uncompressed_size))) {
200+
while ((bits_total > bit_position) && ((uncompressed_size == -1) || (output_data.position() <= uncompressed_size))) {
201201
int character = get_token();
202202
if (character <= 255) { //# literal.
203203
output_data.put((byte) character);
@@ -208,12 +208,11 @@ else if (character == 510) {
208208
else {
209209
int length = character - 253; //# Min length is 3. 256-253=3.
210210
int back = get_position() + 1;
211-
int position = output_data.array().length - back;
211+
int position = output_data.position() - back;
212212
if (back > length){
213213
//# Entire lookback is already within output data.
214214
output_data.put(Arrays.copyOfRange(output_data.array(), position, position + length));
215-
}
216-
else {
215+
} else {
217216
//# Will read & write the same data at some point.
218217
for (int i = position, s = position + length; i < s; i++) {
219218
output_data.put(output_data.get(i));

core/src/main/java/org/embroideryio/embroideryio/EmbPattern.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -944,8 +944,8 @@ public static EmbPattern.Reader getReaderByFilename(String filename) {
944944
return new BroReader();
945945
case "col":
946946
return new ColReader();
947-
case "csd":
948-
return new CsdReader();
947+
// case "csd":
948+
// return new CsdReader();
949949
case "csv":
950950
return new CsvReader();
951951
case "dat":

core/src/main/java/org/embroideryio/embroideryio/HusReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void read() throws IOException {
5252
ByteBuffer x_decompressed = EmbCompress.expand(ByteBuffer.wrap(x_bytes), number_of_stitches);
5353

5454
seek(y_offset);
55-
byte[] y_bytes = this.stream.readAllBytes(); //readfully
55+
byte[] y_bytes = readAllBytes(); //readfully
5656
readFully(y_bytes);
5757
ByteBuffer y_decompressed = EmbCompress.expand(ByteBuffer.wrap(y_bytes), number_of_stitches);
5858

core/src/main/java/org/embroideryio/embroideryio/ReadHelper.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.embroideryio.embroideryio;
22

3+
import java.io.ByteArrayOutputStream;
34
import java.io.IOException;
45
import java.io.InputStream;
56
import java.util.ArrayList;
@@ -109,6 +110,18 @@ public int readFully(byte[] data) throws IOException {
109110
return (read) ? offset : -1;
110111
}
111112

113+
public byte[] readAllBytes() throws IOException {
114+
InputStream s = stream;
115+
int bufferLength = 1024;
116+
byte[] buffer = new byte[bufferLength];
117+
int bytesRead;
118+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
119+
while ((bytesRead = s.read(buffer, 0, bufferLength)) != -1) {
120+
outputStream.write(buffer, 0, bytesRead);
121+
}
122+
return outputStream.toByteArray();
123+
}
124+
112125
public static int signed8(int v) {
113126
v &= 0xFF;
114127
if (v > 0x7F) {

0 commit comments

Comments
 (0)