18 for(
size_t index=0; index<file_count; index++)
25 const std::string &filename):
26 m_zip_archive(filename)
37 m_zip_archive(data, size)
45 : m_zip_archive(std::move(other.m_zip_archive)),
46 m_name_to_index(std::move(other.m_name_to_index))
67 catch(
const std::runtime_error &)
88 const std::string::const_iterator begin,
89 const std::string::const_iterator end)
91 const auto out_begin=std::find_if_not(begin, end,
is_space);
92 const auto out_end=std::find_if_not(
93 std::string::const_reverse_iterator(end),
94 std::string::const_reverse_iterator(out_begin),
96 return { out_begin, out_end };
101 const auto entry=
get_entry(
"META-INF/MANIFEST.MF");
103 if(!entry.has_value())
106 std::unordered_map<std::string, std::string> out;
107 std::istringstream in(*entry);
109 while(std::getline(in, line))
111 const auto key_end=std::find(line.cbegin(), line.cend(),
':');
112 if(key_end!=line.cend())
115 trim(line.cbegin(), key_end),
116 trim(std::next(key_end), line.cend()));
125 std::vector<std::string> out;
127 out.emplace_back(pair.first);
Class representing a .jar archive.
mz_zip_archivet m_zip_archive
jar_filet & operator=(const jar_filet &)=delete
std::unordered_map< std::string, size_t > m_name_to_index
Map of filename to the file index in the zip archive.
std::optional< std::string > get_entry(const std::string &filename)
Get contents of a file in the jar archive.
std::vector< std::string > filenames() const
Get list of filenames in the archive.
jar_filet(const std::string &filename)
Open java file for reading.
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)
void initialize_file_index()
Loads the fileindex (m_name_to_index) with a map of loaded files to indices.
size_t get_num_files()
Get number of files in the archive.
std::string extract(size_t index)
Get contents of nth file in the archive.
std::string get_filename(size_t index)
Get file name of nth file in the archive.
static std::string trim(const std::string::const_iterator begin, const std::string::const_iterator end)
Remove leading and trailing whitespace characters from string.
static bool is_space(const char ch)
Wrapper for std::isspace from cctype