1 -- | This module defines functions to read Java JAR files.
2 module Java.JAR.Archive where
4 import qualified Codec.Archive.LibZip as Zip
6 import qualified Data.ByteString.Lazy as B
8 import Java.ClassPath.Types
9 import Java.ClassPath.Common
13 readJAREntry :: (Enum a) => FilePath -> String -> IO (Maybe [a])
14 readJAREntry jarfile path = do
15 Zip.catchZipError (Just `fmap` (Zip.withArchive [] jarfile $ Zip.fileContents [] path))
16 (\_ -> return Nothing)
18 -- | Read all entires from JAR file
19 readAllJAR :: FilePath -> IO [Tree CPEntry]
20 readAllJAR jarfile = do
21 files <- Zip.withArchive [] jarfile $ Zip.fileNames []
22 return $ mapF (NotLoadedJAR jarfile) (buildTree files)
24 -- | Read one class from JAR file
25 readFromJAR :: FilePath -> FilePath -> IO (Class Direct)
26 readFromJAR jarfile path = do
27 content <- Zip.withArchive [] jarfile $ Zip.fileContents [] path
28 let bstr = B.pack content
29 return $ classFile2Direct (decode bstr)