使用SharpZipLib解压缩.Jar文件 [英] Unzipping .Jar files with SharpZipLib

查看:91
本文介绍了使用SharpZipLib解压缩.Jar文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了文章,了解如何使用以下方法解压缩jar文件ICSharpCode.SharpZipLib,只需要一小部分代码;

I followed an article on here on how to unzip jar files using ICSharpCode.SharpZipLib, needing only a small portion of the code that being;

Dim fz As New FastZip()
     fz.ExtractZip(jarpath, savefolderpath, "")



但是我尝试解压缩的特定jar文件导致问题,我得到了错误;



However the particular jar file I''m trying to unzip is causing a problem, I get the error;

ArguementOutOfRangeException was unhandled
Specified argument was out of the range of valid values.
Parameter name: length


尝试提取时.自从收到此错误以来,我已经阅读了有关它的MSDN文章(勉强了解它们),并制作了一些测试jar文件(它们提取得很好).

我查看了提取的文件夹,看可能是什么原因引起的错误,结果是有一个名为"null"的文件链接到其他几个.class文件,导致提取引起此错误.

使用WinRAR时,空文件以提取和压缩形式显示0kb文件大小.

我想知道是否仍然可以解决此错误?

请记住,我还是VB的新手.


When trying to extract it. Since getting this error I''ve read the MSDN articles on it (barely understanding them) and made some test jar files (they extracted fine).

I looked into the extracted folder to see what might be causing the error, it turns out there''s a file named ''null'' that is linked to several other .class files causing the extraction to throw this error.

The null file shows 0kb file size in both extracted and zipped form when using WinRAR.

I was wondering if there was anyway to get around this error?

Please keep in mind I''m still new to VB.

推荐答案

这似乎是库中可能的错误.您可能需要下载源代码,看看是否可以找到故障点,并添加一些代码来解决该问题.
That looks like a possible bug in the library. You probably need to download the source and see if you can find the point of failure and add some code to work round it.


我不了解C#,这就是lib的含义.写道.

无论如何,我都会下载源代码,并从中得知这两种语言之间的相似之处,以了解我对它的理解.知道我可能需要在源代码中找到什么吗?




下载了源文件后,我在VS 2010中打开了它们,并开始一次浏览文件,我遇到了这段代码,但是并没有完全理解它是否引起了我的问题.我看到了异常,所以我以为这是罪魁祸首.

I have no understanding of C#, which is what the lib is wrote in.

I''ll download the source anyway and see what I can understand of it, from what I''ve been told there are similarities between the two languages. Any idea what I might need to look for in the source code?




Having downloaded the source files I opened them in VS 2010 and started looking through the files one at a time, I came across this bit of code but don''t fully understand if it''s causing my problem. I see the exception I''m getting, so I''m assuming this is the culprit.

/// <summary>
		/// Add a new entry to extra data
		/// </summary>
		/// <param name="headerID">The ID for this entry.</param>
		/// <param name="fieldData">The data to add.</param>
		/// <remarks>If the ID already exists its contents are replaced.</remarks>
		public void AddEntry(int headerID, byte[] fieldData)
		{
			if ( (headerID > ushort.MaxValue) || (headerID < 0)) {
				throw new ArgumentOutOfRangeException("headerID");
			}

			int addLength = (fieldData == null) ? 0 : fieldData.Length;

			if ( addLength > ushort.MaxValue ) {
#if NETCF_1_0
				throw new ArgumentOutOfRangeException("fieldData");
#else
				throw new ArgumentOutOfRangeException("fieldData", "exceeds maximum length");
#endif
			}

			// Test for new length before adjusting data.
			int newLength = _data.Length + addLength + 4;

			if ( Find(headerID) )
			{
				newLength -= (ValueLength + 4);
			}

			if ( newLength > ushort.MaxValue ) {
				throw new ZipException("Data exceeds maximum length");
			}
			
			Delete(headerID);

			byte[] newData = new byte[newLength];
			_data.CopyTo(newData, 0);
			int index = _data.Length;
			_data = newData;
			SetShort(ref index, headerID);
			SetShort(ref index, addLength);
			if ( fieldData != null ) {
				fieldData.CopyTo(newData, index);
			}
		}


我根据Richard的建议进行了更具体的搜索,并得到了2个与他的建议完全吻合的结果.

搜索1在名为
I did a more specific search based on what Richard suggested and got 2 results that are verbatim with his suggestion.

Search 1 is in a file titled
InflaterInputStream.cs


的文件中



/// <summary>
		/// Read clear text data from the input stream.
		/// </summary>
		/// <param name="outBuffer">The buffer to add data to.</param>
		/// <param name="offset">The offset to start adding data at.</param>
		/// <param name="length">The number of bytes to read.</param>
		/// <returns>Returns the number of bytes actually read.</returns>
		public int ReadClearTextBuffer(byte[] outBuffer, int offset, int length)
		{
			if ( length < 0 ) {
				throw new ArgumentOutOfRangeException("length");
			}
			
			int currentOffset = offset;
			int currentLength = length;
			
			while ( currentLength > 0 ) {
				if ( available <= 0 ) {
					Fill();
					if (available <= 0) {
						return 0;
					}
				}
				
				int toCopy = Math.Min(currentLength, available);
				Array.Copy(clearText, clearTextLength - (int)available, outBuffer, currentOffset, toCopy);
				currentOffset += toCopy;
				currentLength -= toCopy;
				available -= toCopy;
			}
			return length;
		}





搜索2位于名为





Search 2 is in a file called

StreamManipulator.cs

的文件中(为了不发布大量代码,我将仅发布该异常);

(for the sake of not posting a ton of code I''ll only post the exception);

/// <exception cref="ArgumentOutOfRangeException">
		/// Length is less than zero
		/// </exception>
public int CopyBytes(byte[] output, int offset, int length)
		{
			if (length < 0) {
				throw new ArgumentOutOfRangeException("length");
			}



有关搜索的更多描述性注释2;



More descriptive notes for search 2;

/// <summary>
		/// Copies bytes from input buffer to output buffer starting
		/// at output[offset].  You have to make sure, that the buffer is
		/// byte aligned.  If not enough bytes are available, copies fewer
		/// bytes.
		/// </summary>





找到问题后,如何在不破坏lib的情况下进行修复?我真的对使用C#编码一无所知.它像删除"if"语句或更改值一样简单吗?


我只是删除了引发异常的"if"语句,它运行良好.





With the problem found, how can I fix it without breaking the lib? I really don''t know anything about coding with C#. Is it as simple as removing the ''if'' statement or changing the value?


I simply deleted the ''if'' statements that throws the Exception and it''s working perfectly.


这篇关于使用SharpZipLib解压缩.Jar文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆