mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
code formatting style has been fixed
This commit is contained in:
parent
5680ad3353
commit
a8cdc40ca5
2 changed files with 68 additions and 68 deletions
|
@ -25,15 +25,15 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
|
||||||
import org.geometerplus.zlibrary.core.util.*;
|
import org.geometerplus.zlibrary.core.util.*;
|
||||||
|
|
||||||
public class ZLFileImage extends ZLSingleImage {
|
public class ZLFileImage extends ZLSingleImage {
|
||||||
public static final String SCHEME = "imagefile";
|
public static final String SCHEME = "imagefile";
|
||||||
|
|
||||||
public static final String ENCODING_NONE = "";
|
public static final String ENCODING_NONE = "";
|
||||||
public static final String ENCODING_HEX = "hex";
|
public static final String ENCODING_HEX = "hex";
|
||||||
public static final String ENCODING_BASE64 = "base64";
|
public static final String ENCODING_BASE64 = "base64";
|
||||||
|
|
||||||
public static ZLFileImage byUrlPath(String urlPath) {
|
public static ZLFileImage byUrlPath(String urlPath) {
|
||||||
try {
|
try {
|
||||||
final String[] data = urlPath.split("\000");
|
final String[] data = urlPath.split("\000");
|
||||||
int count = Integer.parseInt(data[2]);
|
int count = Integer.parseInt(data[2]);
|
||||||
int[] offsets = new int[count];
|
int[] offsets = new int[count];
|
||||||
int[] lengths = new int[count];
|
int[] lengths = new int[count];
|
||||||
|
@ -41,21 +41,21 @@ public class ZLFileImage extends ZLSingleImage {
|
||||||
offsets[i] = Integer.parseInt(data[3 + i]);
|
offsets[i] = Integer.parseInt(data[3 + i]);
|
||||||
lengths[i] = Integer.parseInt(data[3 + count + i]);
|
lengths[i] = Integer.parseInt(data[3 + count + i]);
|
||||||
}
|
}
|
||||||
return new ZLFileImage(
|
return new ZLFileImage(
|
||||||
MimeType.IMAGE_AUTO,
|
MimeType.IMAGE_AUTO,
|
||||||
ZLFile.createFileByPath(data[0]),
|
ZLFile.createFileByPath(data[0]),
|
||||||
data[1],
|
data[1],
|
||||||
offsets,
|
offsets,
|
||||||
lengths
|
lengths
|
||||||
);
|
);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ZLFile myFile;
|
private final ZLFile myFile;
|
||||||
private final String myEncoding;
|
private final String myEncoding;
|
||||||
private final int[] myOffsets;
|
private final int[] myOffsets;
|
||||||
private final int[] myLengths;
|
private final int[] myLengths;
|
||||||
|
|
||||||
|
@ -71,11 +71,11 @@ public class ZLFileImage extends ZLSingleImage {
|
||||||
myLengths = lengths;
|
myLengths = lengths;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLFileImage(String mimeType, ZLFile file, String encoding, int offset, int length) {
|
public ZLFileImage(String mimeType, ZLFile file, String encoding, int offset, int length) {
|
||||||
this(MimeType.get(mimeType), file, encoding, offset, length);
|
this(MimeType.get(mimeType), file, encoding, offset, length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int offset, int length) {
|
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int offset, int length) {
|
||||||
super(mimeType);
|
super(mimeType);
|
||||||
myFile = file;
|
myFile = file;
|
||||||
myEncoding = encoding != null ? encoding : ENCODING_NONE;
|
myEncoding = encoding != null ? encoding : ENCODING_NONE;
|
||||||
|
@ -83,13 +83,13 @@ public class ZLFileImage extends ZLSingleImage {
|
||||||
myLengths = new int[1];
|
myLengths = new int[1];
|
||||||
myOffsets[0] = offset;
|
myOffsets[0] = offset;
|
||||||
myLengths[0] = length;
|
myLengths[0] = length;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ZLFileImage(MimeType mimeType, ZLFile file) {
|
public ZLFileImage(MimeType mimeType, ZLFile file) {
|
||||||
this(mimeType, file, ENCODING_NONE, 0, (int)file.size());
|
this(mimeType, file, ENCODING_NONE, 0, (int)file.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getURI() {
|
public String getURI() {
|
||||||
String result = SCHEME + "://" + myFile.getPath() + "\000" + myEncoding + "\000" + myOffsets.length;
|
String result = SCHEME + "://" + myFile.getPath() + "\000" + myEncoding + "\000" + myOffsets.length;
|
||||||
for (int offset : myOffsets) {
|
for (int offset : myOffsets) {
|
||||||
result += "\000" + offset;
|
result += "\000" + offset;
|
||||||
|
@ -98,11 +98,11 @@ public class ZLFileImage extends ZLSingleImage {
|
||||||
result += "\000" + length;
|
result += "\000" + length;
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream inputStream() {
|
public InputStream inputStream() {
|
||||||
try {
|
try {
|
||||||
final InputStream stream;
|
final InputStream stream;
|
||||||
if (myOffsets.length == 1) {
|
if (myOffsets.length == 1) {
|
||||||
final int offset = myOffsets[0];
|
final int offset = myOffsets[0];
|
||||||
|
@ -118,18 +118,18 @@ public class ZLFileImage extends ZLSingleImage {
|
||||||
stream = new MergedInputStream(streams);
|
stream = new MergedInputStream(streams);
|
||||||
}
|
}
|
||||||
if (ENCODING_NONE.equals(myEncoding)) {
|
if (ENCODING_NONE.equals(myEncoding)) {
|
||||||
return stream;
|
return stream;
|
||||||
} else if (ENCODING_HEX.equals(myEncoding)) {
|
} else if (ENCODING_HEX.equals(myEncoding)) {
|
||||||
return new HexInputStream(stream);
|
return new HexInputStream(stream);
|
||||||
} else if (ENCODING_BASE64.equals(myEncoding)) {
|
} else if (ENCODING_BASE64.equals(myEncoding)) {
|
||||||
return new Base64InputStream(stream);
|
return new Base64InputStream(stream);
|
||||||
} else {
|
} else {
|
||||||
System.err.println("unsupported encoding: " + myEncoding);
|
System.err.println("unsupported encoding: " + myEncoding);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,14 +27,14 @@ public class MergedInputStream extends InputStream {
|
||||||
private InputStream myCurrentStream;
|
private InputStream myCurrentStream;
|
||||||
private int myCurrentStreamNumber;
|
private int myCurrentStreamNumber;
|
||||||
|
|
||||||
public MergedInputStream(InputStream[] streams) throws IOException {
|
public MergedInputStream(InputStream[] streams) throws IOException {
|
||||||
myStreams = streams;
|
myStreams = streams;
|
||||||
myCurrentStream = streams[0];
|
myCurrentStream = streams[0];
|
||||||
myCurrentStreamNumber = 0;
|
myCurrentStreamNumber = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read() throws IOException {
|
public int read() throws IOException {
|
||||||
int readed = -1;
|
int readed = -1;
|
||||||
boolean streamIsAvailable = true;
|
boolean streamIsAvailable = true;
|
||||||
while (readed == -1 && streamIsAvailable) {
|
while (readed == -1 && streamIsAvailable) {
|
||||||
|
@ -44,10 +44,10 @@ public class MergedInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return readed;
|
return readed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int read(byte[] b, int off, int len) throws IOException {
|
public int read(byte[] b, int off, int len) throws IOException {
|
||||||
int bytesToRead = len;
|
int bytesToRead = len;
|
||||||
int bytesReaded = 0;
|
int bytesReaded = 0;
|
||||||
boolean streamIsAvailable = true;
|
boolean streamIsAvailable = true;
|
||||||
|
@ -63,10 +63,10 @@ public class MergedInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bytesReaded == 0 ? -1 : bytesReaded;
|
return bytesReaded == 0 ? -1 : bytesReaded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public long skip(long n) throws IOException {
|
public long skip(long n) throws IOException {
|
||||||
long skipped = myCurrentStream.skip(n);
|
long skipped = myCurrentStream.skip(n);
|
||||||
boolean streamIsAvailable = true;
|
boolean streamIsAvailable = true;
|
||||||
while (skipped < n && streamIsAvailable) {
|
while (skipped < n && streamIsAvailable) {
|
||||||
|
@ -76,25 +76,25 @@ public class MergedInputStream extends InputStream {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return skipped;
|
return skipped;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int available() throws IOException {
|
public int available() throws IOException {
|
||||||
int total = 0;
|
int total = 0;
|
||||||
for (int i = myCurrentStreamNumber; i < myStreams.length; ++i) {
|
for (int i = myCurrentStreamNumber; i < myStreams.length; ++i) {
|
||||||
total += myStreams[i].available();
|
total += myStreams[i].available();
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void reset() throws IOException {
|
public void reset() throws IOException {
|
||||||
myCurrentStream = myStreams[0];
|
myCurrentStream = myStreams[0];
|
||||||
myCurrentStreamNumber = 0;
|
myCurrentStreamNumber = 0;
|
||||||
for (InputStream stream : myStreams) {
|
for (InputStream stream : myStreams) {
|
||||||
stream.reset();
|
stream.reset();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean nextStream() {
|
private boolean nextStream() {
|
||||||
if (myCurrentStreamNumber + 1 >= myStreams.length) {
|
if (myCurrentStreamNumber + 1 >= myStreams.length) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue