public void getFileTarHeader ( TarHeader hdr , File file ) throws InvalidHeaderException { this . file = file ; String name = file . getPath ( ) ; String osname = System . getProperty ( "os.name" ) ; if ( osname != null ) { // Strip off drive letters! // REVIEW Would a better check be "(File.separator == '\')"? // String Win32Prefix = "Windows"; // String prefix = osname.substring( 0, Win32Prefix.length() ); // if ( prefix.equalsIgnoreCase( Win32Prefix ) ) // if ( File.separatorChar == '\\' ) // Windows OS check was contributed by // Patrick Beard <beard@netscape.com> String Win32Prefix = "windows" ; if ( osname . toLowerCase ( ) . startsWith ( Win32Prefix ) ) { if ( name . length ( ) > 2 ) { char ch1 = name . charAt ( 0 ) ; char ch2 = name . charAt ( 1 ) ; if ( ch2 == ' ' && ( ( ch1 >= ' ' && ch1 <= ' ' ) || ( ch1 >= ' ' && ch1 <= ' ' ) ) ) { name = name . substring ( 2 ) ; } } } } name = name . replace ( File . separatorChar , ' ' ) ; // No absolute pathnames // Windows (and Posix?) paths can start with "\\NetworkDrive\", // so we loop on starting /'s. for ( ; name . startsWith ( "/" ) ; ) { name = name . substring ( 1 ) ; } hdr . linkName = new StringBuffer ( "" ) ; hdr . name = new StringBuffer ( name ) ; if ( file . isDirectory ( ) ) { hdr . size = 0 ; hdr . mode = 040755 ; hdr . linkFlag = TarHeader . LF_DIR ; if ( hdr . name . charAt ( hdr . name . length ( ) - 1 ) != ' ' ) { hdr . name . append ( "/" ) ; } } else { hdr . size = file . length ( ) ; hdr . mode = 0100644 ; hdr . linkFlag = TarHeader . LF_NORMAL ; } // UNDONE When File lets us get the userName, use it! hdr . modTime = file . lastModified ( ) / 1000 ; hdr . checkSum = 0 ; hdr . devMajor = 0 ; hdr . devMinor = 0 ; }
Fill in a TarHeader with information from a File .