1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 18:29:23 +02:00

formatting cleanup

This commit is contained in:
Nikolay Pultsin 2013-02-01 15:55:02 +00:00
parent fcafd8120a
commit dc59bf47e4
102 changed files with 498 additions and 498 deletions

View file

@ -4,47 +4,47 @@ import java.util.*;
import java.io.*; import java.io.*;
public abstract class Decompressor { public abstract class Decompressor {
public Decompressor(MyBufferedInputStream is, LocalFileHeader header) { public Decompressor(MyBufferedInputStream is, LocalFileHeader header) {
} }
/** /**
* byte b[] -- target buffer for bytes; might be null * byte b[] -- target buffer for bytes; might be null
*/ */
public abstract int read(byte b[], int off, int len) throws IOException; public abstract int read(byte b[], int off, int len) throws IOException;
public abstract int read() throws IOException; public abstract int read() throws IOException;
protected Decompressor() { protected Decompressor() {
} }
private static Queue<DeflatingDecompressor> ourDeflators = new LinkedList<DeflatingDecompressor>(); private static Queue<DeflatingDecompressor> ourDeflators = new LinkedList<DeflatingDecompressor>();
static void storeDecompressor(Decompressor decompressor) { static void storeDecompressor(Decompressor decompressor) {
if (decompressor instanceof DeflatingDecompressor) { if (decompressor instanceof DeflatingDecompressor) {
synchronized (ourDeflators) { synchronized (ourDeflators) {
ourDeflators.add((DeflatingDecompressor)decompressor); ourDeflators.add((DeflatingDecompressor)decompressor);
} }
} }
} }
static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws IOException { static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws IOException {
switch (header.CompressionMethod) { switch (header.CompressionMethod) {
case 0: case 0:
return new NoCompressionDecompressor(is, header); return new NoCompressionDecompressor(is, header);
case 8: case 8:
synchronized (ourDeflators) { synchronized (ourDeflators) {
if (!ourDeflators.isEmpty()) { if (!ourDeflators.isEmpty()) {
DeflatingDecompressor decompressor = ourDeflators.poll(); DeflatingDecompressor decompressor = ourDeflators.poll();
decompressor.reset(is, header); decompressor.reset(is, header);
return decompressor; return decompressor;
} }
} }
return new DeflatingDecompressor(is, header); return new DeflatingDecompressor(is, header);
default: default:
throw new ZipException("Unsupported method of compression"); throw new ZipException("Unsupported method of compression");
} }
} }
public int available() throws IOException { public int available() throws IOException {
return -1; return -1;
} }
} }

View file

@ -8,31 +8,31 @@ package org.amse.ys.zip;
import java.io.IOException; import java.io.IOException;
public class LocalFileHeader { public class LocalFileHeader {
static final int FILE_HEADER_SIGNATURE = 0x04034b50; static final int FILE_HEADER_SIGNATURE = 0x04034b50;
static final int FOLDER_HEADER_SIGNATURE = 0x02014b50; static final int FOLDER_HEADER_SIGNATURE = 0x02014b50;
static final int END_OF_CENTRAL_DIRECTORY_SIGNATURE = 0x06054b50; static final int END_OF_CENTRAL_DIRECTORY_SIGNATURE = 0x06054b50;
static final int DATA_DESCRIPTOR_SIGNATURE = 0x08074b50; static final int DATA_DESCRIPTOR_SIGNATURE = 0x08074b50;
int Signature; int Signature;
int Version; int Version;
int Flags; int Flags;
int CompressionMethod; int CompressionMethod;
int ModificationTime; int ModificationTime;
int ModificationDate; int ModificationDate;
int CRC32; int CRC32;
int CompressedSize; int CompressedSize;
int UncompressedSize; int UncompressedSize;
int NameLength; int NameLength;
int ExtraLength; int ExtraLength;
public String FileName; public String FileName;
int DataOffset; int DataOffset;
LocalFileHeader() { LocalFileHeader() {
} }
void readFrom(MyBufferedInputStream stream) throws IOException { void readFrom(MyBufferedInputStream stream) throws IOException {
Signature = stream.read4Bytes(); Signature = stream.read4Bytes();
switch (Signature) { switch (Signature) {
default: default:
@ -40,26 +40,26 @@ public class LocalFileHeader {
case END_OF_CENTRAL_DIRECTORY_SIGNATURE: case END_OF_CENTRAL_DIRECTORY_SIGNATURE:
{ {
stream.skip(16); stream.skip(16);
int comment = stream.read2Bytes(); int comment = stream.read2Bytes();
stream.skip(comment); stream.skip(comment);
break; break;
} }
case FOLDER_HEADER_SIGNATURE: case FOLDER_HEADER_SIGNATURE:
{ {
Version = stream.read4Bytes(); Version = stream.read4Bytes();
Flags = stream.read2Bytes(); Flags = stream.read2Bytes();
CompressionMethod = stream.read2Bytes(); CompressionMethod = stream.read2Bytes();
ModificationTime = stream.read2Bytes(); ModificationTime = stream.read2Bytes();
ModificationDate = stream.read2Bytes(); ModificationDate = stream.read2Bytes();
CRC32 = stream.read4Bytes(); CRC32 = stream.read4Bytes();
CompressedSize = stream.read4Bytes(); CompressedSize = stream.read4Bytes();
UncompressedSize = stream.read4Bytes(); UncompressedSize = stream.read4Bytes();
if (CompressionMethod == 0 && CompressedSize != UncompressedSize) { if (CompressionMethod == 0 && CompressedSize != UncompressedSize) {
CompressedSize = UncompressedSize; CompressedSize = UncompressedSize;
} }
NameLength = stream.read2Bytes(); NameLength = stream.read2Bytes();
ExtraLength = stream.read2Bytes(); ExtraLength = stream.read2Bytes();
int comment = stream.read2Bytes(); int comment = stream.read2Bytes();
stream.skip(12); stream.skip(12);
FileName = stream.readString(NameLength); FileName = stream.readString(NameLength);
stream.skip(ExtraLength); stream.skip(ExtraLength);
@ -67,19 +67,19 @@ public class LocalFileHeader {
break; break;
} }
case FILE_HEADER_SIGNATURE: case FILE_HEADER_SIGNATURE:
Version = stream.read2Bytes(); Version = stream.read2Bytes();
Flags = stream.read2Bytes(); Flags = stream.read2Bytes();
CompressionMethod = stream.read2Bytes(); CompressionMethod = stream.read2Bytes();
ModificationTime = stream.read2Bytes(); ModificationTime = stream.read2Bytes();
ModificationDate = stream.read2Bytes(); ModificationDate = stream.read2Bytes();
CRC32 = stream.read4Bytes(); CRC32 = stream.read4Bytes();
CompressedSize = stream.read4Bytes(); CompressedSize = stream.read4Bytes();
UncompressedSize = stream.read4Bytes(); UncompressedSize = stream.read4Bytes();
if (CompressionMethod == 0 && CompressedSize != UncompressedSize) { if (CompressionMethod == 0 && CompressedSize != UncompressedSize) {
CompressedSize = UncompressedSize; CompressedSize = UncompressedSize;
} }
NameLength = stream.read2Bytes(); NameLength = stream.read2Bytes();
ExtraLength = stream.read2Bytes(); ExtraLength = stream.read2Bytes();
FileName = stream.readString(NameLength); FileName = stream.readString(NameLength);
stream.skip(ExtraLength); stream.skip(ExtraLength);
break; break;
@ -90,5 +90,5 @@ public class LocalFileHeader {
break; break;
} }
DataOffset = stream.offset(); DataOffset = stream.offset();
} }
} }

View file

@ -3,40 +3,40 @@ package org.amse.ys.zip;
import java.io.*; import java.io.*;
public class NoCompressionDecompressor extends Decompressor { public class NoCompressionDecompressor extends Decompressor {
private final LocalFileHeader myHeader; private final LocalFileHeader myHeader;
private final MyBufferedInputStream myStream; private final MyBufferedInputStream myStream;
private int myCurrentPosition; private int myCurrentPosition;
public NoCompressionDecompressor(MyBufferedInputStream is, LocalFileHeader header) { public NoCompressionDecompressor(MyBufferedInputStream is, LocalFileHeader header) {
super(); super();
myHeader = header; myHeader = header;
myStream = is; myStream = is;
} }
public int read(byte b[], int off, int len) throws IOException { public int read(byte b[], int off, int len) throws IOException {
int i = 0; int i = 0;
for (; i < len; ++i) { for (; i < len; ++i) {
int value = read(); int value = read();
if (value == -1) { if (value == -1) {
break; break;
}
if (b != null) {
b[off + i] = (byte)value;
} }
} if (b != null) {
return (i > 0) ? i : -1; b[off + i] = (byte)value;
} }
}
return (i > 0) ? i : -1;
}
public int read() throws IOException { public int read() throws IOException {
if (myCurrentPosition < myHeader.CompressedSize) { if (myCurrentPosition < myHeader.CompressedSize) {
myCurrentPosition++; myCurrentPosition++;
return myStream.read(); return myStream.read();
} else { } else {
return -1; return -1;
} }
} }
public int available() throws IOException { public int available() throws IOException {
return (myHeader.UncompressedSize - myCurrentPosition); return (myHeader.UncompressedSize - myCurrentPosition);
} }
} }

View file

@ -4,7 +4,7 @@ import java.io.IOException;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ZipException extends IOException { public class ZipException extends IOException {
ZipException(String message) { ZipException(String message) {
super(message); super(message);
} }
} }

View file

@ -4,48 +4,48 @@ import java.io.*;
class ZipInputStream extends InputStream { class ZipInputStream extends InputStream {
private final ZipFile myParent; private final ZipFile myParent;
private final MyBufferedInputStream myBaseStream; private final MyBufferedInputStream myBaseStream;
private final Decompressor myDecompressor; private final Decompressor myDecompressor;
private boolean myIsClosed; private boolean myIsClosed;
public ZipInputStream(ZipFile parent, LocalFileHeader header) throws IOException { public ZipInputStream(ZipFile parent, LocalFileHeader header) throws IOException {
myParent = parent; myParent = parent;
myBaseStream = parent.getBaseStream(); myBaseStream = parent.getBaseStream();
myBaseStream.setPosition(header.DataOffset); myBaseStream.setPosition(header.DataOffset);
myDecompressor = Decompressor.init(myBaseStream, header); myDecompressor = Decompressor.init(myBaseStream, header);
} }
@Override @Override
public int available() throws IOException { public int available() throws IOException {
return myDecompressor.available(); return myDecompressor.available();
} }
@Override @Override
public int read(byte b[], int off, int len) throws IOException { public int read(byte b[], int off, int len) throws IOException {
if (b == null) { if (b == null) {
throw new NullPointerException(); throw new NullPointerException();
} else if ((off < 0) || (off > b.length) || (len < 0) || } else if ((off < 0) || (off > b.length) || (len < 0) ||
((off + len) > b.length) || ((off + len) < 0)) { ((off + len) > b.length) || ((off + len) < 0)) {
throw new IndexOutOfBoundsException(); throw new IndexOutOfBoundsException();
} else if (len == 0) { } else if (len == 0) {
return 0; return 0;
} }
return myDecompressor.read(b, off, len); return myDecompressor.read(b, off, len);
} }
@Override @Override
public int read() throws IOException { public int read() throws IOException {
return myDecompressor.read(); return myDecompressor.read();
} }
public void close() throws IOException { public void close() throws IOException {
if (!myIsClosed) { if (!myIsClosed) {
myIsClosed = true; myIsClosed = true;
myParent.storeBaseStream(myBaseStream); myParent.storeBaseStream(myBaseStream);
Decompressor.storeDecompressor(myDecompressor); Decompressor.storeDecompressor(myDecompressor);
} }
} }
protected void finalize() throws Throwable { protected void finalize() throws Throwable {
try { try {

View file

@ -35,29 +35,29 @@ public class TapZoneMap {
ourPredefinedMaps.add("left_to_right"); ourPredefinedMaps.add("left_to_right");
ourPredefinedMaps.add("down"); ourPredefinedMaps.add("down");
ourPredefinedMaps.add("up"); ourPredefinedMaps.add("up");
ourMapsOption = new ZLStringListOption("TapZones", "List", ourPredefinedMaps, "\000"); ourMapsOption = new ZLStringListOption("TapZones", "List", ourPredefinedMaps, "\000");
} }
private static final Map<String,TapZoneMap> ourMaps = new HashMap<String,TapZoneMap>(); private static final Map<String,TapZoneMap> ourMaps = new HashMap<String,TapZoneMap>();
public static List<String> zoneMapNames() { public static List<String> zoneMapNames() {
return ourMapsOption.getValue(); return ourMapsOption.getValue();
} }
public static TapZoneMap zoneMap(String name) { public static TapZoneMap zoneMap(String name) {
TapZoneMap map = ourMaps.get(name); TapZoneMap map = ourMaps.get(name);
if (map == null) { if (map == null) {
map = new TapZoneMap(name); map = new TapZoneMap(name);
ourMaps.put(name, map); ourMaps.put(name, map);
} }
return map; return map;
} }
public static TapZoneMap createZoneMap(String name, int width, int height) { public static TapZoneMap createZoneMap(String name, int width, int height) {
if (ourMapsOption.getValue().contains(name)) { if (ourMapsOption.getValue().contains(name)) {
return null; return null;
} }
final TapZoneMap map = zoneMap(name); final TapZoneMap map = zoneMap(name);
map.myWidth.setValue(width); map.myWidth.setValue(width);
map.myHeight.setValue(height); map.myHeight.setValue(height);
final List<String> lst = new LinkedList<String>(ourMapsOption.getValue()); final List<String> lst = new LinkedList<String>(ourMapsOption.getValue());
@ -68,10 +68,10 @@ public class TapZoneMap {
public static void deleteZoneMap(String name) { public static void deleteZoneMap(String name) {
if (ourPredefinedMaps.contains(name)) { if (ourPredefinedMaps.contains(name)) {
return; return;
} }
ourMaps.remove(name); ourMaps.remove(name);
final List<String> lst = new LinkedList<String>(ourMapsOption.getValue()); final List<String> lst = new LinkedList<String>(ourMapsOption.getValue());
lst.remove(name); lst.remove(name);
@ -84,15 +84,15 @@ public class TapZoneMap {
doubleTap doubleTap
}; };
public final String Name; public final String Name;
private final String myOptionGroupName; private final String myOptionGroupName;
private ZLIntegerRangeOption myHeight; private ZLIntegerRangeOption myHeight;
private ZLIntegerRangeOption myWidth; private ZLIntegerRangeOption myWidth;
private final HashMap<Zone,ZLStringOption> myZoneMap = new HashMap<Zone,ZLStringOption>(); private final HashMap<Zone,ZLStringOption> myZoneMap = new HashMap<Zone,ZLStringOption>();
private final HashMap<Zone,ZLStringOption> myZoneMap2 = new HashMap<Zone,ZLStringOption>(); private final HashMap<Zone,ZLStringOption> myZoneMap2 = new HashMap<Zone,ZLStringOption>();
private TapZoneMap(String name) { private TapZoneMap(String name) {
Name = name; Name = name;
myOptionGroupName = "TapZones:" + name; myOptionGroupName = "TapZones:" + name;
myHeight = new ZLIntegerRangeOption(myOptionGroupName, "Height", 2, 5, 3); myHeight = new ZLIntegerRangeOption(myOptionGroupName, "Height", 2, 5, 3);
myWidth = new ZLIntegerRangeOption(myOptionGroupName, "Width", 2, 5, 3); myWidth = new ZLIntegerRangeOption(myOptionGroupName, "Width", 2, 5, 3);
@ -103,15 +103,15 @@ public class TapZoneMap {
} }
public boolean isCustom() { public boolean isCustom() {
return !ourPredefinedMaps.contains(Name); return !ourPredefinedMaps.contains(Name);
} }
public int getHeight() { public int getHeight() {
return myHeight.getValue(); return myHeight.getValue();
} }
public int getWidth() { public int getWidth() {
return myWidth.getValue(); return myWidth.getValue();
} }
public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) { public String getActionByCoordinates(int x, int y, int width, int height, Tap tap) {
@ -126,40 +126,40 @@ public class TapZoneMap {
return option != null ? option.getValue() : null; return option != null ? option.getValue() : null;
} }
private ZLStringOption getOptionByZone(Zone zone, Tap tap) { private ZLStringOption getOptionByZone(Zone zone, Tap tap) {
switch (tap) { switch (tap) {
default: default:
return null; return null;
case singleTap: case singleTap:
{ {
final ZLStringOption option = myZoneMap.get(zone); final ZLStringOption option = myZoneMap.get(zone);
return option != null ? option : myZoneMap2.get(zone); return option != null ? option : myZoneMap2.get(zone);
} }
case singleNotDoubleTap: case singleNotDoubleTap:
return myZoneMap.get(zone); return myZoneMap.get(zone);
case doubleTap: case doubleTap:
return myZoneMap2.get(zone); return myZoneMap2.get(zone);
} }
} }
private ZLStringOption createOptionForZone(Zone zone, boolean singleTap, String action) { private ZLStringOption createOptionForZone(Zone zone, boolean singleTap, String action) {
return new ZLStringOption( return new ZLStringOption(
myOptionGroupName, myOptionGroupName,
(singleTap ? "Action" : "Action2") + ":" + zone.HIndex + ":" + zone.VIndex, (singleTap ? "Action" : "Action2") + ":" + zone.HIndex + ":" + zone.VIndex,
action action
); );
} }
public void setActionForZone(int h, int v, boolean singleTap, String action) { public void setActionForZone(int h, int v, boolean singleTap, String action) {
final Zone zone = new Zone(h, v); final Zone zone = new Zone(h, v);
final HashMap<Zone,ZLStringOption> map = singleTap ? myZoneMap : myZoneMap2; final HashMap<Zone,ZLStringOption> map = singleTap ? myZoneMap : myZoneMap2;
ZLStringOption option = map.get(zone); ZLStringOption option = map.get(zone);
if (option == null) { if (option == null) {
option = createOptionForZone(zone, singleTap, null); option = createOptionForZone(zone, singleTap, null);
map.put(zone, option); map.put(zone, option);
} }
option.setValue(action); option.setValue(action);
} }
private static class Zone { private static class Zone {
int HIndex; int HIndex;
@ -202,9 +202,9 @@ public class TapZoneMap {
try { try {
if ("zone".equals(tag)) { if ("zone".equals(tag)) {
final Zone zone = new Zone( final Zone zone = new Zone(
Integer.parseInt(attributes.getValue("x")), Integer.parseInt(attributes.getValue("x")),
Integer.parseInt(attributes.getValue("y")) Integer.parseInt(attributes.getValue("y"))
); );
final String action = attributes.getValue("action"); final String action = attributes.getValue("action");
final String action2 = attributes.getValue("action2"); final String action2 = attributes.getValue("action2");
if (action != null) { if (action != null) {

View file

@ -73,12 +73,12 @@ class ZLTarHeader {
if (linkFlag == -1) { if (linkFlag == -1) {
return false; return false;
} }
IsRegularFile = (linkFlag == 0) || (linkFlag == (byte)'0'); IsRegularFile = linkFlag == 0 || linkFlag == (byte)'0';
stream.skip(355); stream.skip(355);
if (((linkFlag == (byte)'L') || if ((linkFlag == (byte)'L' || linkFlag == (byte)'K')
(linkFlag == (byte)'K')) && (Name == "././@LongLink") && (Size < 10240)) { && "././@LongLink".equals(Name) && Size < 10240) {
final byte[] nameBuffer = new byte[Size - 1]; final byte[] nameBuffer = new byte[Size - 1];
stream.read(nameBuffer); stream.read(nameBuffer);
Name = getStringFromByteArray(nameBuffer); Name = getStringFromByteArray(nameBuffer);

View file

@ -25,111 +25,111 @@ 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];
for (int i = 0; i < count; ++i) { for (int i = 0; i < count; ++i) {
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;
public ZLFileImage(String mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) { public ZLFileImage(String mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
this(MimeType.get(mimeType), file, encoding, offsets, lengths); this(MimeType.get(mimeType), file, encoding, offsets, lengths);
} }
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) { public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
super(mimeType); super(mimeType);
myFile = file; myFile = file;
myEncoding = encoding != null ? encoding : ENCODING_NONE; myEncoding = encoding != null ? encoding : ENCODING_NONE;
myOffsets = offsets; myOffsets = offsets;
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;
myOffsets = new int[1]; myOffsets = new int[1];
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;
} }
for (int length : myLengths) { for (int length : myLengths) {
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];
final int length = myLengths[0]; final int length = myLengths[0];
stream = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE); stream = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
} else { } else {
final InputStream[] streams = new InputStream[myOffsets.length]; final InputStream[] streams = new InputStream[myOffsets.length];
for (int i = 0; i < myOffsets.length; ++i) { for (int i = 0; i < myOffsets.length; ++i) {
final int offset = myOffsets[i]; final int offset = myOffsets[i];
final int length = myLengths[i]; final int length = myLengths[i];
streams[i] = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE); streams[i] = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
} }
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;
} }
} }
} }

View file

@ -172,8 +172,8 @@ abstract class ZLTextViewBase extends ZLView {
} }
protected final ZLPaintContext.ScalingType getScalingType(ZLTextImageElement imageElement) { protected final ZLPaintContext.ScalingType getScalingType(ZLTextImageElement imageElement) {
switch (getImageFitting()) { switch (getImageFitting()) {
default: default:
case none: case none:
return ZLPaintContext.ScalingType.IntegerCoefficient; return ZLPaintContext.ScalingType.IntegerCoefficient;
case covers: case covers: