CBMC
jar_filet Class Referencefinal

Class representing a .jar archive. More...

#include <jar_file.h>

+ Collaboration diagram for jar_filet:

Public Member Functions

 jar_filet (const std::string &filename)
 Open java file for reading. More...
 
 jar_filet (const void *data, size_t size)
 Open a JAR file of size size loaded in memory at address data. More...
 
 jar_filet (const jar_filet &)=delete
 
jar_filetoperator= (const jar_filet &)=delete
 
 jar_filet (jar_filet &&)
 
jar_filetoperator= (jar_filet &&)
 
 ~jar_filet ()=default
 
std::optional< std::string > get_entry (const std::string &filename)
 Get contents of a file in the jar archive. More...
 
std::unordered_map< std::string, std::string > get_manifest ()
 Get contents of the Manifest file in the jar archive as a key-value map (both as strings) More...
 
std::vector< std::string > filenames () const
 Get list of filenames in the archive. More...
 

Private Member Functions

void initialize_file_index ()
 Loads the fileindex (m_name_to_index) with a map of loaded files to indices. More...
 

Private Attributes

mz_zip_archivet m_zip_archive
 
std::unordered_map< std::string, size_t > m_name_to_index
 Map of filename to the file index in the zip archive. More...
 

Detailed Description

Class representing a .jar archive.

Uses miniz to decompress and index archive.

Definition at line 21 of file jar_file.h.

Constructor & Destructor Documentation

◆ jar_filet() [1/4]

jar_filet::jar_filet ( const std::string &  filename)
explicit

Open java file for reading.

This constructor creates a jar_file object whose contents are extracted from a file with given name.

Parameters
filenameName of the file
Exceptions
Throwsstd::runtime_error if file cannot be opened

Definition at line 24 of file jar_file.cpp.

◆ jar_filet() [2/4]

jar_filet::jar_filet ( const void *  data,
size_t  size 
)

Open a JAR file of size size loaded in memory at address data.

This constructor creates a jar_file object whose contents are extracted from a memory buffer (byte array) as opposed to a jar file.

Parameters
datamemory buffer with the contents of the jar file
sizesize of the memory buffer
Exceptions
Throwsstd::runtime_error if data is not in correct format

Definition at line 34 of file jar_file.cpp.

◆ jar_filet() [3/4]

jar_filet::jar_filet ( const jar_filet )
delete

◆ jar_filet() [4/4]

jar_filet::jar_filet ( jar_filet &&  other)

Definition at line 44 of file jar_file.cpp.

◆ ~jar_filet()

jar_filet::~jar_filet ( )
default

Member Function Documentation

◆ filenames()

std::vector< std::string > jar_filet::filenames ( ) const

Get list of filenames in the archive.

Definition at line 123 of file jar_file.cpp.

◆ get_entry()

std::optional< std::string > jar_filet::get_entry ( const std::string &  filename)

Get contents of a file in the jar archive.

Returns nullopt if file doesn't exist.

Parameters
filenameName of the file in the archive

Definition at line 57 of file jar_file.cpp.

◆ get_manifest()

std::unordered_map< std::string, std::string > jar_filet::get_manifest ( )

Get contents of the Manifest file in the jar archive as a key-value map (both as strings)

Definition at line 99 of file jar_file.cpp.

◆ initialize_file_index()

void jar_filet::initialize_file_index ( )
private

Loads the fileindex (m_name_to_index) with a map of loaded files to indices.

Definition at line 15 of file jar_file.cpp.

◆ operator=() [1/2]

jar_filet& jar_filet::operator= ( const jar_filet )
delete

◆ operator=() [2/2]

jar_filet & jar_filet::operator= ( jar_filet &&  other)

Definition at line 50 of file jar_file.cpp.

Member Data Documentation

◆ m_name_to_index

std::unordered_map<std::string, size_t> jar_filet::m_name_to_index
private

Map of filename to the file index in the zip archive.

Definition at line 61 of file jar_file.h.

◆ m_zip_archive

mz_zip_archivet jar_filet::m_zip_archive
private

Definition at line 58 of file jar_file.h.


The documentation for this class was generated from the following files: