1
0
Fork 0
mirror of https://github.com/geometer/FBReaderJ.git synced 2025-10-05 10:49:24 +02:00

more items

git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@1308 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
Nikolay Pultsin 2010-04-29 22:37:42 +00:00
parent dbe5bad5ea
commit 1c3661dfa2
12 changed files with 72 additions and 37 deletions

View file

@ -15,6 +15,9 @@ DONE убрать иконку сетевого поиска из библиот
** NetworkSearchService
DONE модель + функционал поиска
** отображение результатов
** изменить вид библиотеки -- вместо дерева -- последовательные view без сдвига вправо (как в маркете)
** при нажатии на кнопку 'Esc' -- возвращаться к предыдущему view + прерывать загрузку, если она еще идет
** соответственно, каталог должен иметь не 2 состояния -- загружен/не загружен, а загружен полностью/не полностью/не загружен; в случае загрузки не полностью можно при повторном открытии продолжать загрузку с точки, где прервались (для тех каталогов, что подделены на куски по 20 (или сколько-то) книг
** восставление пароля (use default e-mail)
** пополнение счета в litres с помощью sms
** Focus в Authentication dialog

View file

@ -1 +1 @@
0.6.2
0.6.3

View file

@ -1,5 +1,7 @@
package org.amse.ys.zip;
import java.io.IOException;
abstract class AbstractDeflatingDecompressor extends Decompressor {
abstract void reset(MyBufferedInputStream inputStream, LocalFileHeader header);
abstract void reset(MyBufferedInputStream inputStream, LocalFileHeader header) throws IOException;
}

View file

@ -1,5 +1,7 @@
package org.amse.ys.zip;
import java.io.IOException;
final class CircularBuffer {
static final int DICTIONARY_LENGTH = (1 << 15);
private static final int DICTIONARY_MASK = DICTIONARY_LENGTH - 1;
@ -33,9 +35,9 @@ final class CircularBuffer {
myBytesReady -= length;
}
public byte read() {
public byte read() throws IOException {
if (myBytesReady == 0) {
throw new RuntimeException("reading from empty buffer");
throw new ZipException("reading from empty buffer");
}
final byte result = myBuffer[myCurrentPosition++];
myCurrentPosition &= DICTIONARY_MASK;
@ -48,9 +50,9 @@ final class CircularBuffer {
myBytesReady++;
}
public void repeat(int length, int distance) {
public void repeat(int length, int distance) throws IOException {
if (myBytesReady + length > DICTIONARY_LENGTH) {
throw new RuntimeException("circular buffer overflow");
throw new ZipException("circular buffer overflow");
}
int writePoint = (myCurrentPosition + myBytesReady) & DICTIONARY_MASK;
int readPoint = (writePoint - distance) & DICTIONARY_MASK;

View file

@ -23,7 +23,7 @@ public abstract class Decompressor {
}
}
public static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws ZipException {
public static Decompressor init(MyBufferedInputStream is, LocalFileHeader header) throws IOException {
switch (header.CompressionMethod) {
case 0:
return new NoCompressionDecompressor(is, header);
@ -44,7 +44,7 @@ public abstract class Decompressor {
}
}
public int available() {
public int available() throws IOException {
return -1;
}
}

View file

@ -34,12 +34,12 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
private final int[] myDistanceCodes = new int[1 << 15];
private final int[] myAuxCodes = new int[1 << 15];
public DeflatingDecompressor(MyBufferedInputStream inputStream, LocalFileHeader header) {
public DeflatingDecompressor(MyBufferedInputStream inputStream, LocalFileHeader header) throws IOException {
super();
reset(inputStream, header);
}
void reset(MyBufferedInputStream inputStream, LocalFileHeader header) {
void reset(MyBufferedInputStream inputStream, LocalFileHeader header) throws IOException {
myStream = inputStream;
myHeader = header;
myTotalLength = header.getCompressedSize();
@ -55,7 +55,7 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
}
@Override
public int available() {
public int available() throws IOException {
return myHeader.getUncompressedSize() - myCurrentPosition;
}
@ -225,7 +225,7 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
}
distance = previousCode + 1 + readIntegerByBit(extraBits);
} else {
throw new RuntimeException("distance code > 29 found");
throw new ZipException("distance code > 29 found");
}
myOutputBuffer.repeat(length, distance);
return length;
@ -253,7 +253,7 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
private void readHeader() throws IOException {
if ((myState != ST_HEADER) || (myBytesRead >= myTotalLength)) {
throw new RuntimeException("unexpected case of readheader call");
throw new ZipException("unexpected case of readheader call");
}
myTheBlockIsFinal = (getBit() != 0);
switch (readIntegerByBit(2)) {
@ -327,7 +327,7 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
previous = false;
break;
default:
throw new RuntimeException("error when reading dynamic Huffman codes");
throw new ZipException("error when reading dynamic Huffman codes");
}
previousNumber = previous ? previousNumber : 0;
for (int j = 0; j < repeatNumber; j++) {
@ -366,7 +366,7 @@ public class DeflatingDecompressor extends AbstractDeflatingDecompressor {
previous = false;
break;
default:
throw new RuntimeException("error when reading dynamic Huffman codes");
throw new ZipException("error when reading dynamic Huffman codes");
}
previousNumber = (previous ? previousNumber : 0);
for (int j = 0; j < repeatNumber; j++) {

View file

@ -5,13 +5,15 @@ package org.amse.ys.zip;
* construcor, all fields are final.
*/
import java.io.IOException;
public class LocalFileHeader {
/**
* Initilization of constants. Implements: versions, ...
*/
static final int FILE_HEADER_SIGNATURE = 0x04034b50;
static final int FOLDER_HEADER_SIGNATURE = 0x02014b50;
static final int DATA_DESCRIPTOR_SIGNATURE = 0x504b0708;
static final int DATA_DESCRIPTOR_SIGNATURE = 0x07084b50;
final int VersionNeededToExtract;
final int GeneralPurposeFlag;
@ -25,7 +27,6 @@ public class LocalFileHeader {
LocalFileHeader(int versionNeededToExtract, int generalPurposeFlag,
int compressionMethod, int compressedSize, int uncompressedSize,
int offsetOfLocalData, String fileName) {
VersionNeededToExtract = versionNeededToExtract;
GeneralPurposeFlag = generalPurposeFlag;
CompressionMethod = compressionMethod;
@ -40,20 +41,20 @@ public class LocalFileHeader {
return mySizeIsKnown;
}
int getCompressedSize() {
int getCompressedSize() throws IOException {
if (mySizeIsKnown) {
return myCompressedSize;
} else {
throw new RuntimeException(
throw new ZipException(
"Error in getCompressedSize: file size is not known yet");
}
}
int getUncompressedSize() {
int getUncompressedSize() throws IOException {
if (mySizeIsKnown) {
return myUncompressedSize;
} else {
throw new RuntimeException(
throw new ZipException(
"Error in getUncompressedSize: file size is not known yet");
}
}

View file

@ -30,12 +30,12 @@ public class NativeDeflatingDecompressor extends AbstractDeflatingDecompressor {
private int myOutBufferOffset;
private int myOutBufferLength;
public NativeDeflatingDecompressor(MyBufferedInputStream inputStream, LocalFileHeader header) {
public NativeDeflatingDecompressor(MyBufferedInputStream inputStream, LocalFileHeader header) throws IOException {
super();
reset(inputStream, header);
}
void reset(MyBufferedInputStream inputStream, LocalFileHeader header) {
void reset(MyBufferedInputStream inputStream, LocalFileHeader header) throws IOException {
endInflating();
myStream = inputStream;

View file

@ -34,7 +34,7 @@ public class NoCompressionDecompressor extends Decompressor {
}
}
public int available() {
public int available() throws IOException {
return (myHeader.getUncompressedSize() - myCurrentPosition);
}
}

View file

@ -20,6 +20,7 @@ public final class ZipFile {
}
}
private String PATH;
private final InputStreamHolder myStreamHolder;
private final LinkedHashMap<String,LocalFileHeader> myFileHeaders = new LinkedHashMap<String,LocalFileHeader>();
@ -27,6 +28,7 @@ public final class ZipFile {
public ZipFile(String filePath) {
this(new FileInputStreamHolder(filePath));
PATH = filePath;
}
public ZipFile(InputStreamHolder streamHolder) {
@ -99,6 +101,7 @@ public final class ZipFile {
* Finds descriptor of the last header and installs sizes of files
*/
private void findAndReadDescriptor(MyBufferedInputStream baseStream, LocalFileHeader header) throws IOException {
loop:
while (true) {
int signature = 0;
do {
@ -107,18 +110,30 @@ public final class ZipFile {
throw new ZipException(
"readFileHeaders. Unexpected end of file when looking for DataDescriptor");
}
signature = ((signature << 8) & (0x0FFFFFFFF)) + (byte) nextByte;
} while (signature != LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE);
baseStream.skip(4);
int compressedSize = baseStream.read4Bytes();
int uncompressedSize = baseStream.read4Bytes();
if ((baseStream.offset() - header.OffsetOfLocalData - 16) == compressedSize) {
header.setSizes(compressedSize, uncompressedSize);
break;
} else {
baseStream.backSkip(12);
continue;
}
signature = ((signature >> 8) & 0x0FFFFFF) | (nextByte << 24);
} while (
signature != LocalFileHeader.FILE_HEADER_SIGNATURE &&
signature != LocalFileHeader.FOLDER_HEADER_SIGNATURE &&
signature != LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE
);
System.err.println(PATH + " : " + Integer.toHexString(signature));
switch (signature) {
case LocalFileHeader.FILE_HEADER_SIGNATURE:
break loop;
case LocalFileHeader.FOLDER_HEADER_SIGNATURE:
break loop;
case LocalFileHeader.DATA_DESCRIPTOR_SIGNATURE:
baseStream.skip(4);
int compressedSize = baseStream.read4Bytes();
int uncompressedSize = baseStream.read4Bytes();
if ((baseStream.offset() - header.OffsetOfLocalData - 16) == compressedSize) {
header.setSizes(compressedSize, uncompressedSize);
break loop;
} else {
baseStream.backSkip(12);
continue loop;
}
}
}
}

View file

@ -19,7 +19,7 @@ class ZipInputStream extends InputStream {
}
@Override
public int available() {
public int available() throws IOException {
return myDecompressor.available();
}

View file

@ -42,6 +42,7 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
System.err.println("onCreate");
Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler(this));
requestWindowFeature(Window.FEATURE_NO_TITLE);
@ -73,6 +74,7 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onStart() {
super.onStart();
System.err.println("onStart");
switch (ourOrientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
@ -88,9 +90,16 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onPause() {
ZLApplication.Instance().onWindowClosing();
System.err.println("onPause");
super.onPause();
}
@Override
public void onResume() {
System.err.println("onResume");
super.onResume();
}
@Override
public void onNewIntent(Intent intent) {
super.onNewIntent(intent);
@ -148,6 +157,9 @@ public abstract class ZLAndroidActivity extends Activity {
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
Configuration defaultConfig = new Configuration();
defaultConfig.setToDefaults();
System.err.println("config = " + config);
switch (getRequestedOrientation()) {
default: