當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。