1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-04 10:19:33 +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.*;
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
*/
public abstract int read(byte b[], int off, int len) throws IOException;
public abstract int read() throws IOException;
public abstract int read(byte b[], int off, int len) 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) {
if (decompressor instanceof DeflatingDecompressor) {
synchronized (ourDeflators) {
ourDeflators.add((DeflatingDecompressor)decompressor);
}
}
}
static void storeDecompressor(Decompressor decompressor) {
if (decompressor instanceof DeflatingDecompressor) {
synchronized (ourDeflators) {
ourDeflators.add((DeflatingDecompressor)decompressor);
}
}
}
static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws IOException {
switch (header.CompressionMethod) {
case 0:
return new NoCompressionDecompressor(is, header);
case 8:
synchronized (ourDeflators) {
if (!ourDeflators.isEmpty()) {
DeflatingDecompressor decompressor = ourDeflators.poll();
decompressor.reset(is, header);
return decompressor;
}
}
return new DeflatingDecompressor(is, header);
default:
throw new ZipException("Unsupported method of compression");
}
}
static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws IOException {
switch (header.CompressionMethod) {
case 0:
return new NoCompressionDecompressor(is, header);
case 8:
synchronized (ourDeflators) {
if (!ourDeflators.isEmpty()) {
DeflatingDecompressor decompressor = ourDeflators.poll();
decompressor.reset(is, header);
return decompressor;
}
}
return new DeflatingDecompressor(is, header);
default:
throw new ZipException("Unsupported method of compression");
}
}
public int available() throws IOException {
return -1;
}
public int available() throws IOException {
return -1;
}
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -25,111 +25,111 @@ import org.geometerplus.zlibrary.core.filesystem.ZLFile;
import org.geometerplus.zlibrary.core.util.*;
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_HEX = "hex";
public static final String ENCODING_BASE64 = "base64";
public static final String ENCODING_NONE = "";
public static final String ENCODING_HEX = "hex";
public static final String ENCODING_BASE64 = "base64";
public static ZLFileImage byUrlPath(String urlPath) {
try {
final String[] data = urlPath.split("\000");
int count = Integer.parseInt(data[2]);
int[] offsets = new int[count];
int[] lengths = new int[count];
for (int i = 0; i < count; ++i) {
offsets[i] = Integer.parseInt(data[3 + i]);
lengths[i] = Integer.parseInt(data[3 + count + i]);
}
return new ZLFileImage(
MimeType.IMAGE_AUTO,
ZLFile.createFileByPath(data[0]),
data[1],
offsets,
lengths
);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static ZLFileImage byUrlPath(String urlPath) {
try {
final String[] data = urlPath.split("\000");
int count = Integer.parseInt(data[2]);
int[] offsets = new int[count];
int[] lengths = new int[count];
for (int i = 0; i < count; ++i) {
offsets[i] = Integer.parseInt(data[3 + i]);
lengths[i] = Integer.parseInt(data[3 + count + i]);
}
return new ZLFileImage(
MimeType.IMAGE_AUTO,
ZLFile.createFileByPath(data[0]),
data[1],
offsets,
lengths
);
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private final ZLFile myFile;
private final String myEncoding;
private final int[] myOffsets;
private final int[] myLengths;
private final ZLFile myFile;
private final String myEncoding;
private final int[] myOffsets;
private final int[] myLengths;
public ZLFileImage(String mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
this(MimeType.get(mimeType), file, encoding, offsets, lengths);
}
public ZLFileImage(String mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
this(MimeType.get(mimeType), file, encoding, offsets, lengths);
}
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
super(mimeType);
myFile = file;
myEncoding = encoding != null ? encoding : ENCODING_NONE;
myOffsets = offsets;
myLengths = lengths;
}
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int[] offsets, int[] lengths) {
super(mimeType);
myFile = file;
myEncoding = encoding != null ? encoding : ENCODING_NONE;
myOffsets = offsets;
myLengths = lengths;
}
public ZLFileImage(String mimeType, ZLFile file, String encoding, int offset, int length) {
this(MimeType.get(mimeType), file, encoding, offset, length);
}
public ZLFileImage(String mimeType, ZLFile file, String encoding, int offset, int length) {
this(MimeType.get(mimeType), file, encoding, offset, length);
}
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int offset, int length) {
super(mimeType);
myFile = file;
myEncoding = encoding != null ? encoding : ENCODING_NONE;
myOffsets = new int[1];
myLengths = new int[1];
myOffsets[0] = offset;
myLengths[0] = length;
}
public ZLFileImage(MimeType mimeType, ZLFile file, String encoding, int offset, int length) {
super(mimeType);
myFile = file;
myEncoding = encoding != null ? encoding : ENCODING_NONE;
myOffsets = new int[1];
myLengths = new int[1];
myOffsets[0] = offset;
myLengths[0] = length;
}
public ZLFileImage(MimeType mimeType, ZLFile file) {
this(mimeType, file, ENCODING_NONE, 0, (int)file.size());
}
public ZLFileImage(MimeType mimeType, ZLFile file) {
this(mimeType, file, ENCODING_NONE, 0, (int)file.size());
}
public String getURI() {
String result = SCHEME + "://" + myFile.getPath() + "\000" + myEncoding + "\000" + myOffsets.length;
for (int offset : myOffsets) {
result += "\000" + offset;
}
for (int length : myLengths) {
result += "\000" + length;
}
return result;
}
public String getURI() {
String result = SCHEME + "://" + myFile.getPath() + "\000" + myEncoding + "\000" + myOffsets.length;
for (int offset : myOffsets) {
result += "\000" + offset;
}
for (int length : myLengths) {
result += "\000" + length;
}
return result;
}
@Override
public InputStream inputStream() {
try {
final InputStream stream;
if (myOffsets.length == 1) {
final int offset = myOffsets[0];
final int length = myLengths[0];
stream = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
} else {
final InputStream[] streams = new InputStream[myOffsets.length];
for (int i = 0; i < myOffsets.length; ++i) {
final int offset = myOffsets[i];
final int length = myLengths[i];
streams[i] = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
}
stream = new MergedInputStream(streams);
}
if (ENCODING_NONE.equals(myEncoding)) {
return stream;
} else if (ENCODING_HEX.equals(myEncoding)) {
return new HexInputStream(stream);
} else if (ENCODING_BASE64.equals(myEncoding)) {
return new Base64InputStream(stream);
} else {
System.err.println("unsupported encoding: " + myEncoding);
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
@Override
public InputStream inputStream() {
try {
final InputStream stream;
if (myOffsets.length == 1) {
final int offset = myOffsets[0];
final int length = myLengths[0];
stream = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
} else {
final InputStream[] streams = new InputStream[myOffsets.length];
for (int i = 0; i < myOffsets.length; ++i) {
final int offset = myOffsets[i];
final int length = myLengths[i];
streams[i] = new SliceInputStream(myFile.getInputStream(), offset, length != 0 ? length : Integer.MAX_VALUE);
}
stream = new MergedInputStream(streams);
}
if (ENCODING_NONE.equals(myEncoding)) {
return stream;
} else if (ENCODING_HEX.equals(myEncoding)) {
return new HexInputStream(stream);
} else if (ENCODING_BASE64.equals(myEncoding)) {
return new Base64InputStream(stream);
} else {
System.err.println("unsupported encoding: " + myEncoding);
return null;
}
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
}

View file

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