corda/src/finder.h
Joel Dice d0a6096eb0 add support for accessing embedded JARs as if they were directories
This allows OpenJDK to access time zone data which is normally found
under java.home, but which we must embed in the executable itself to
create a self-contained build.  The VM intercepts various file
operations, looking for paths which start with a prefix specified by
the avian.embed.prefix property and redirecting those operations to an
embedded JAR.

For example, if avian.embed.prefix is "/avian-embedded", and code
calls File.exists() with a path of
"/avian-embedded/javahomeJar/foo.txt", the VM looks for a function
named javahomeJar via dlsym, calls the function to find the memory
region containing the embeded JAR, and finally consults the JAR to see
if the file "foo.txt" exists.
2010-11-05 13:18:28 -06:00

80 lines
1.7 KiB
C++

/* Copyright (c) 2008, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
#ifndef FINDER_H
#define FINDER_H
#include "common.h"
#include "system.h"
#include "allocator.h"
namespace vm {
class Finder {
public:
class IteratorImp {
public:
virtual const char* next(unsigned* size) = 0;
virtual void dispose() = 0;
};
class Iterator {
public:
Iterator(Finder* finder):
it(finder->iterator()),
current(it->next(&currentSize))
{ }
~Iterator() {
it->dispose();
}
bool hasMore() {
if (current) return true;
current = it->next(&currentSize);
return current != 0;
}
const char* next(unsigned* size) {
if (hasMore()) {
*size = currentSize;
const char* v = current;
current = 0;
return v;
} else {
return 0;
}
}
IteratorImp* it;
const char* current;
unsigned currentSize;
};
virtual IteratorImp* iterator() = 0;
virtual System::Region* find(const char* name) = 0;
virtual System::FileType stat(const char* name,
unsigned* length,
bool tryDirectory = false) = 0;
virtual const char* path() = 0;
virtual void dispose() = 0;
};
Finder*
makeFinder(System* s, Allocator* a, const char* path, const char* bootLibrary);
Finder*
makeFinder(System* s, Allocator* a, const uint8_t* jarData,
unsigned jarLength);
} // namespace vm
#endif//FINDER_H