commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From yogeshrai <yogeshronl...@gmail.com>
Subject Re: [compress] not able to set extra field ExtendedTimestamp using commons.compress.archivers.zip
Date Sun, 03 Nov 2013 18:15:00 GMT
Thnx a lot Stefan for prompt reply.I did made necessary change as suggested
by u.Still even when i set all 3 date types to old date and then try to
extract via default archive manager , m stuck with current date time for
individual files bundled in.

M i missing anything more here.M using ubuntu 12.0X as test machine
here.common compress 1.6 jar in use.


Here's update test class.

class EOSUnixSystemCall
{
	public static void main (String args[])  {
		EOSUnixSystemCall.compressFolder("/home/yogeshrai/testdir",
"/home/yogeshrai/testdir/testzip");
    	
    }
	public static void compressFolder(String sourceFolder, String
absoluteZipfilepath)
    {
    	try
    	{
	    	File srcFolder = new File(sourceFolder);
	    	if(srcFolder != null && srcFolder.isDirectory())
		    {
	    		Iterator<File> i = FileUtils.iterateFiles(srcFolder,null, true);
                       

	    		File zipFile = new File(absoluteZipfilepath);
	    		zipFile.createNewFile();
	    		OutputStream outputStream = new FileOutputStream(zipFile);
	    		ArchiveOutputStream zipOutputStream = new
ZipArchiveOutputStream(outputStream);
	    		int srcFolderLength = srcFolder.getAbsolutePath().length() + 1;  //
+1 to remove the last file separator
	    		while(i.hasNext())
	    		{
	    			File file = i.next();
                    String relativePath  =
file.getAbsolutePath().substring(srcFolderLength);
                    ZipArchiveEntry zipArchiveEntry = new
ZipArchiveEntry(relativePath);
	    			
	    			//add extended timestamp extra field for zip archive entry
					Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
					cal.set(Calendar.YEAR, 1998);
					cal.set(Calendar.MONTH, Calendar.JANUARY);
					cal.set(Calendar.DATE, 1);
					cal.set(Calendar.HOUR_OF_DAY, 0);
					cal.set(Calendar.MINUTE, 0);
					cal.set(Calendar.MILLISECOND, 0);
					Date timeMillis = cal.getTime();
					X5455_ExtendedTimestamp xf = new X5455_ExtendedTimestamp();
					xf.setModifyJavaTime(timeMillis);
					xf.setCreateJavaTime(timeMillis);
					xf.setAccessJavaTime(timeMillis);
					xf.setFlags((byte) 4);
					zipArchiveEntry.addExtraField(xf);
					zipOutputStream.putArchiveEntry(zipArchiveEntry);
	    			FileInputStream fis = null;
                   try {
			              fis = new FileInputStream(file);
			              IOUtils.copy(fis , zipOutputStream); 
                      }finally {
						  fis.close();
						  zipOutputStream.closeArchiveEntry();
				    }		    			
	    		}
	    		zipOutputStream.finish();
	    		zipOutputStream.close();
	    		outputStream.close();
		    }
    	}catch (Exception e) {
    		e.printStackTrace();
		}
    	
    }
}



--
View this message in context: http://apache-commons.680414.n4.nabble.com/not-able-to-set-extra-field-ExtendedTimestamp-using-commons-compress-archivers-zip-tp4656283p4656326.html
Sent from the Commons - User mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@commons.apache.org
For additional commands, e-mail: user-help@commons.apache.org


Mime
View raw message