本文整理汇总了Java中java.util.zip.DataFormatException类的典型用法代码示例。如果您正苦于以下问题:Java DataFormatException类的具体用法?Java DataFormatException怎么用?Java DataFormatException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
DataFormatException类属于java.util.zip包,在下文中一共展示了DataFormatException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readChunkUnzip
import java.util.zip.DataFormatException; //导入依赖的package包/类
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
try {
do {
int read = inflater.inflate(buffer, offset, length);
if(read <= 0) {
if(inflater.finished()) {
throw new EOFException();
}
if(inflater.needsInput()) {
refillInflater(inflater);
} else {
throw new IOException("Can't inflate " + length + " bytes");
}
} else {
offset += read;
length -= read;
}
} while(length > 0);
} catch (DataFormatException ex) {
throw (IOException)(new IOException("inflate error").initCause(ex));
}
}
示例2: decompress
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static byte[] decompress(byte[] value) throws DataFormatException
{
ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
Inflater decompressor = new Inflater();
try
{
decompressor.setInput(value);
final byte[] buf = new byte[1024];
while (!decompressor.finished())
{
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} finally
{
decompressor.end();
}
return bos.toByteArray();
}
示例3: uncompress
import java.util.zip.DataFormatException; //导入依赖的package包/类
public int uncompress(byte[] input, int inputOffset, int inputLength, byte[] output, int outputOffset, int maxOutputLength) throws IOException
{
Inflater inf = inflater.get();
inf.reset();
inf.setInput(input, inputOffset, inputLength);
if (inf.needsInput())
return 0;
// We assume output is big enough
try
{
return inf.inflate(output, outputOffset, maxOutputLength);
}
catch (DataFormatException e)
{
throw new IOException(e);
}
}
示例4: decompress
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static byte[] decompress(final byte[] data) {
final Inflater inflater = new Inflater();
inflater.setInput(data);
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(data.length);
final byte[] buffer = new byte[1024];
try {
while (!inflater.finished()) {
int count;
count = inflater.inflate(buffer);
outputStream.write(buffer, 0, count);
}
outputStream.close();
} catch (final DataFormatException | IOException e) {
log.log(Level.SEVERE, e.getMessage(), e);
}
return outputStream.toByteArray();
}
示例5: decode
import java.util.zip.DataFormatException; //导入依赖的package包/类
@Override
public void decode() {
if (buffer().readableBytes() < 2) return;
try {
setBuffer(Compression.inflate(buffer()));
} catch (DataFormatException e) {
e.printStackTrace();
return;
}
if (buffer().readableBytes() == 0) {
throw new RuntimeException("Decoded BatchPacket payload is empty");
}
buffer().readerIndex(2);
while (buffer().readerIndex() < buffer().readableBytes()) {
PacketRegistry.handlePacket(new RakNetPacket(readBytes()), getPlayer());
}
}
示例6: consume
import java.util.zip.DataFormatException; //导入依赖的package包/类
@Override
public void consume(byte[] buf, int offset, int length) throws IOException {
checkNotClosed();
mInflater.setInput(buf, offset, length);
if (mOutputBuffer == null) {
mOutputBuffer = new byte[65536];
}
while (!mInflater.finished()) {
int outputChunkSize;
try {
outputChunkSize = mInflater.inflate(mOutputBuffer);
} catch (DataFormatException e) {
throw new IOException("Failed to inflate data", e);
}
if (outputChunkSize == 0) {
return;
}
mDelegate.consume(mOutputBuffer, 0, outputChunkSize);
mOutputByteCount += outputChunkSize;
}
}
示例7: unwrap
import java.util.zip.DataFormatException; //导入依赖的package包/类
@Override
public byte[] unwrap(byte[] bytes) {
inflater.setInput(bytes);
try {
int len;
byte[] buffer = new byte[bytes.length];
while (!inflater.finished()) {
len = inflater.inflate(buffer, 0, buffer.length);
if (len > 0)
unwrapBuffer.write(buffer, 0, len);
}
return unwrapBuffer.toByteArray();
} catch (DataFormatException e) {
throw new RuntimeException("unknown format: " + e.getMessage());
} finally {
inflater.reset();
unwrapBuffer.reset();
}
}
示例8: loadSavedFilterRules
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static JSONObject loadSavedFilterRules(Context context, boolean overwrite) throws IOException, DataFormatException, JSONException {
File file = context.getFileStreamPath("rules");
if (!file.exists())
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
byte[] content = Compressor.readFile(file);
if (!overwrite && content.length > 0) {
String data = new String(Compressor.decompress(content), "UTF-8");
return new JSONObject(data);
} else
return new JSONObject().put("rules", new JSONArray());
}
示例9: loadSavedIdentities
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static JSONObject loadSavedIdentities(Context context, boolean overwrite) throws IOException, DataFormatException, JSONException {
File file = context.getFileStreamPath("identities");
if (!file.exists())
//noinspection ResultOfMethodCallIgnored
file.createNewFile();
byte[] content = Compressor.readFile(file);
if (!overwrite && content.length > 0) {
String data = new String(Compressor.decompress(content), "UTF-8");
return new JSONObject(data);
} else
return new JSONObject().put("identities", new JSONArray());
}
示例10: fromID
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static SSHIdentity fromID(Context context, long id) throws JSONException, IOException, DataFormatException {
JSONArray savedIdentities = SSHIdentity.loadSavedIdentities(context, false).getJSONArray("identities");
for (int i = 0; i < savedIdentities.length(); i++) {
JSONObject identityObj = savedIdentities.getJSONObject(i);
if (identityObj == null)
continue;
if (identityObj.getLong("id") == id) {
return new SSHIdentity(
identityObj.getString("name"),
identityObj.getString("host"),
identityObj.getString("username"),
identityObj.optString("password"),
identityObj.optString("keyFilePath"),
identityObj.optString("keyFilePassword"),
identityObj.getInt("port"),
identityObj.getLong("id")
);
}
}
return new SSHIdentity();
}
示例11: inflate
import java.util.zip.DataFormatException; //导入依赖的package包/类
/**
* Inflate the given byte array by {@link #INFLATED_ARRAY_LENGTH}.
*
* @param bytes the bytes
* @return the array as a string with {@code UTF-8} encoding
*/
public static String inflate(final byte[] bytes) {
final Inflater inflater = new Inflater(true);
final byte[] xmlMessageBytes = new byte[INFLATED_ARRAY_LENGTH];
final byte[] extendedBytes = new byte[bytes.length + 1];
System.arraycopy(bytes, 0, extendedBytes, 0, bytes.length);
extendedBytes[bytes.length] = 0;
inflater.setInput(extendedBytes);
try {
final int resultLength = inflater.inflate(xmlMessageBytes);
inflater.end();
if (!inflater.finished()) {
throw new RuntimeException("buffer not large enough.");
}
inflater.end();
return new String(xmlMessageBytes, 0, resultLength, StandardCharsets.UTF_8);
} catch (final DataFormatException e) {
return null;
}
}
示例12: uncompress
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static byte[] uncompress(byte[] input) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
Inflater decompressor = new Inflater();
try {
decompressor.setInput(input);
final byte[] buf = new byte[2048];
while (!decompressor.finished()) {
int count = 0;
try {
count = decompressor.inflate(buf);
} catch (DataFormatException e) {
e.printStackTrace();
}
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例13: AbstractInternalHDRPercentiles
import java.util.zip.DataFormatException; //导入依赖的package包/类
/**
* Read from a stream.
*/
protected AbstractInternalHDRPercentiles(StreamInput in) throws IOException {
super(in);
format = in.readNamedWriteable(DocValueFormat.class);
keys = in.readDoubleArray();
long minBarForHighestToLowestValueRatio = in.readLong();
final int serializedLen = in.readVInt();
byte[] bytes = new byte[serializedLen];
in.readBytes(bytes, 0, serializedLen);
ByteBuffer stateBuffer = ByteBuffer.wrap(bytes);
try {
state = DoubleHistogram.decodeFromCompressedByteBuffer(stateBuffer, minBarForHighestToLowestValueRatio);
} catch (DataFormatException e) {
throw new IOException("Failed to decode DoubleHistogram for aggregation [" + name + "]", e);
}
keyed = in.readBoolean();
}
示例14: decompress
import java.util.zip.DataFormatException; //导入依赖的package包/类
public static byte[] decompress(byte[] value) throws DataFormatException {
ByteArrayOutputStream bos = new ByteArrayOutputStream(value.length);
Inflater decompressor = new Inflater();
try {
decompressor.setInput(value);
final byte[] buf = new byte[1024];
while (!decompressor.finished()) {
int count = decompressor.inflate(buf);
bos.write(buf, 0, count);
}
} finally {
decompressor.end();
}
return bos.toByteArray();
}
示例15: readChunkUnzip
import java.util.zip.DataFormatException; //导入依赖的package包/类
private void readChunkUnzip(Inflater inflater, byte[] buffer, int offset, int length) throws IOException {
assert(buffer != this.buffer);
try {
do {
int read = inflater.inflate(buffer, offset, length);
if(read <= 0) {
if(inflater.finished()) {
throw new EOFException();
}
if(inflater.needsInput()) {
refillInflater(inflater);
} else {
throw new IOException("Can't inflate " + length + " bytes");
}
} else {
offset += read;
length -= read;
}
} while(length > 0);
} catch (DataFormatException ex) {
throw (IOException)(new IOException("inflate error").initCause(ex));
}
}