22 for(
size_t index=0; index<file_count; index++)
32 const std::string &filename):
33 m_zip_archive(filename)
44 m_zip_archive(
data, size)
52 : m_zip_archive(
std::move(other.m_zip_archive)),
53 m_name_to_index(
std::move(other.m_name_to_index))
74 catch(
const std::runtime_error &)
82 return std::isspace(ch) != 0;
87 const std::string::const_iterator begin,
88 const std::string::const_iterator end)
90 const auto out_begin=std::find_if_not(begin, end,
is_space);
91 const auto out_end=std::find_if_not(
92 std::string::const_reverse_iterator(end),
93 std::string::const_reverse_iterator(out_begin),
95 return { out_begin, out_end };
100 const auto entry=
get_entry(
"META-INF/MANIFEST.MF");
102 if(!entry.has_value())
105 std::unordered_map<std::string, std::string> out;
106 std::istringstream in(*entry);
108 while(std::getline(in, line))
110 const auto key_end=std::find(line.cbegin(), line.cend(),
':');
111 if(key_end!=line.cend())
114 trim(line.cbegin(), key_end),
115 trim(std::next(key_end), line.cend()));
124 std::vector<std::string> out;
126 out.emplace_back(pair.first);
static std::string trim(const std::string::const_iterator begin, const std::string::const_iterator end)
Remove leading and trailing whitespace characters from string.
void initialize_file_index()
Loads the fileindex (m_name_to_index) with a map of loaded files to indices.
std::vector< std::string > filenames() const
Get list of filenames in the archive.
optionalt< std::string > get_entry(const std::string &filename)
Get contents of a file in the jar archive.
std::string extract(size_t index)
Get contents of nth file in the archive.
std::unordered_map< std::string, size_t > m_name_to_index
Map of filename to the file index in the zip archive.
nonstd::optional< T > optionalt
Class representing a .jar archive.
jar_filet(const std::string &filename)
Open java file for reading.
static bool is_space(const char ch)
jar_filet & operator=(const jar_filet &)=delete
mz_zip_archivet m_zip_archive
std::string get_filename(size_t index)
Get file name of nth file in the archive.
size_t get_num_files()
Get number of files in the archive.
std::unordered_map< std::string, std::string > get_manifest()
Get contents of the Manifest file in the jar archive.