当前位置: 首页>>代码示例>>Java>>正文


Java DataFormatException类代码示例

本文整理汇总了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));
    }
}
 
开发者ID:j-dong,项目名称:trashjam2017,代码行数:23,代码来源:PNGDecoder.java

示例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();
}
 
开发者ID:WeDevelopTeam,项目名称:HeroVideo-master,代码行数:25,代码来源:BiliDanmukuCompressionTools.java

示例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);
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:19,代码来源:DeflateCompressor.java

示例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();
}
 
开发者ID:gurkenlabs,项目名称:litiengine,代码行数:22,代码来源:CompressionUtilities.java

示例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());
    }
}
 
开发者ID:KernelFreeze,项目名称:BedrockProxy,代码行数:21,代码来源:BatchPacket.java

示例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;
    }
}
 
开发者ID:F8LEFT,项目名称:FApkSigner,代码行数:22,代码来源:LocalFileRecord.java

示例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();
    }
}
 
开发者ID:ZhangJiupeng,项目名称:AgentX,代码行数:20,代码来源:CompressWrapper.java

示例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());
}
 
开发者ID:SapuSeven,项目名称:NotiCap,代码行数:15,代码来源:FilterRule.java

示例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());
}
 
开发者ID:SapuSeven,项目名称:NotiCap,代码行数:15,代码来源:SSHIdentity.java

示例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();
}
 
开发者ID:SapuSeven,项目名称:NotiCap,代码行数:22,代码来源:SSHIdentity.java

示例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;
    }
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:31,代码来源:CompressionUtils.java

示例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();
}
 
开发者ID:hoangkien0705,项目名称:Android-UtilCode,代码行数:21,代码来源:LogUtils.java

示例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();
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:AbstractInternalHDRPercentiles.java

示例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();
  }
 
开发者ID:MUFCRyan,项目名称:BilibiliClient,代码行数:21,代码来源:BiliDanmukuCompressionTools.java

示例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));
    }
}
 
开发者ID:DaanVanYperen,项目名称:odb-artax,代码行数:24,代码来源:PNGDecoder.java


注:本文中的java.util.zip.DataFormatException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。