Skip to content

Commit

Permalink
Use custom crc digest util
Browse files Browse the repository at this point in the history
  • Loading branch information
REAndroid committed Aug 3, 2024
1 parent 22a5816 commit 3400536
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 25 deletions.
8 changes: 5 additions & 3 deletions src/main/java/com/reandroid/apk/CrcOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,19 @@
*/
package com.reandroid.apk;

import com.reandroid.utils.CRCDigest;

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;

@Deprecated
public class CrcOutputStream extends OutputStream {
private final CRC32 crc;
private final CRCDigest crc;
private long length;
private long mCheckSum;
public CrcOutputStream() {
super();
this.crc = new CRC32();
this.crc = new CRCDigest();
}
public long getLength(){
return length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.json.JSONException;
import com.reandroid.json.JSONObject;
import com.reandroid.utils.CRCDigest;

import java.io.*;

Expand Down Expand Up @@ -58,9 +59,9 @@ public long getLength() throws IOException{
}
@Override
public long getCrc() throws IOException {
CrcOutputStream outputStream=new CrcOutputStream();
CRCDigest outputStream = new CRCDigest();
this.write(outputStream);
return outputStream.getCrcValue();
return outputStream.getValue();
}
public TableBlock getTableBlock() throws IOException{
if(mCache != null){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.reandroid.archive.BlockInputSource;
import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.utils.CRCDigest;

import java.io.*;

Expand Down Expand Up @@ -54,9 +55,9 @@ public long getLength() throws IOException{
}
@Override
public long getCrc() throws IOException {
CrcOutputStream outputStream=new CrcOutputStream();
CRCDigest outputStream = new CRCDigest();
this.write(outputStream);
return outputStream.getCrcValue();
return outputStream.getValue();
}
public TableBlock getTableBlock() throws IOException {
if(mCache!=null){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package com.reandroid.apk.xmlencoder;

import com.reandroid.apk.APKLogger;
import com.reandroid.apk.CrcOutputStream;
import com.reandroid.archive.ByteInputSource;
import com.reandroid.arsc.chunk.PackageBlock;
import com.reandroid.arsc.chunk.xml.ResXmlDocument;
import com.reandroid.utils.CRCDigest;
import com.reandroid.utils.io.IOUtil;
import com.reandroid.xml.source.XMLParserSource;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.io.OutputStream;
import java.util.zip.CRC32;

public class XMLEncodeSource extends ByteInputSource {
private final PackageBlock packageBlock;
Expand All @@ -31,7 +30,7 @@ public long getLength() throws IOException {
}
@Override
public long getCrc() throws IOException{
CRC32 crc32 = new CRC32();
CRCDigest crc32 = new CRCDigest();
byte[] bytes = getArray();
crc32.update(bytes, 0, bytes.length);
return crc32.getValue();
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/reandroid/archive/BlockInputSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
*/
package com.reandroid.archive;

import com.reandroid.apk.CrcOutputStream;
import com.reandroid.arsc.base.Block;
import com.reandroid.arsc.base.BlockRefresh;
import com.reandroid.utils.CRCDigest;

import java.io.IOException;
import java.io.OutputStream;
Expand Down Expand Up @@ -51,9 +51,9 @@ public long getLength() throws IOException{
@Override
public long getCrc() throws IOException{
Block block = getBlock();
CrcOutputStream outputStream=new CrcOutputStream();
CRCDigest outputStream = new CRCDigest();
block.writeBytes(outputStream);
return outputStream.getCrcValue();
return outputStream.getValue();
}
@Override
public long write(OutputStream outputStream) throws IOException {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/reandroid/archive/InputSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@

import com.reandroid.arsc.chunk.TableBlock;
import com.reandroid.arsc.chunk.xml.AndroidManifestBlock;
import com.reandroid.utils.CRCDigest;
import com.reandroid.utils.CompareUtil;
import com.reandroid.utils.StringsUtil;
import com.reandroid.utils.io.FileUtil;

import java.io.*;
import java.util.Comparator;
import java.util.zip.CRC32;

public abstract class InputSource {
private final String name;
Expand Down Expand Up @@ -174,7 +174,7 @@ public String toString(){
private void calculateCrc() throws IOException {
InputStream inputStream=openStream();
long length=0;
CRC32 crc = new CRC32();
CRCDigest crc = new CRCDigest();
int bytesRead;
byte[] buffer = new byte[1024*64];
while((bytesRead = inputStream.read(buffer)) != -1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@
*/
package com.reandroid.archive.io;

import com.reandroid.utils.CRCDigest;
import com.reandroid.utils.HexUtil;

import java.io.IOException;
import java.io.InputStream;
import java.util.zip.CRC32;

public class CountingInputStream<T extends InputStream> extends InputStream {
private final T inputStream;
private final CRC32 crc;
private final CRCDigest crc;
private long size;
private long mCheckSum;
private boolean mFinished;
public CountingInputStream(T inputStream, boolean disableCrc){
this.inputStream = inputStream;
CRC32 crc32;
CRCDigest crc32;
if(disableCrc){
crc32 = null;
}else {
crc32 = new CRC32();
crc32 = new CRCDigest();
}
this.crc = crc32;
}
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/reandroid/archive/io/CountingOutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,24 @@
*/
package com.reandroid.archive.io;

import com.reandroid.utils.CRCDigest;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.zip.CRC32;

public class CountingOutputStream<T extends OutputStream> extends OutputStream {
private final T outputStream;
private CRC32 crc;
private CRCDigest crc;
private long size;
private boolean mClosed;
public CountingOutputStream(T outputStream, boolean disableCrc){
this.outputStream = outputStream;
CRC32 crc32;
CRCDigest crc32;
if(disableCrc){
crc32 = null;
}else {
crc32 = new CRC32();
crc32 = new CRCDigest();
}
this.crc = crc32;
}
Expand All @@ -42,15 +43,15 @@ public CountingOutputStream(T outputStream){
public void disableCrc(boolean disableCrc) {
if(!disableCrc){
if(crc == null){
this.crc = new CRC32();
this.crc = new CRCDigest();
}
}else{
this.crc = null;
}
}

public void reset(){
this.crc = new CRC32();
this.crc = new CRCDigest();
this.size = 0L;
}
public T getOutputStream() {
Expand Down

0 comments on commit 3400536

Please sign in to comment.