本文整理汇总了Java中org.java.plugin.util.IoUtil类的典型用法代码示例。如果您正苦于以下问题:Java IoUtil类的具体用法?Java IoUtil怎么用?Java IoUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IoUtil类属于org.java.plugin.util包,在下文中一共展示了IoUtil类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: service
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
protected void service(HttpServletRequest request, HttpServletResponse response, String resourcePath,
String mimeType) throws IOException
{
final String filename = PathUtils.getFilenameFromFilepath(resourcePath);
if( resourcePath.startsWith("/") )
{
resourcePath = resourcePath.substring(1);
}
final URL res = new URL(pluginService.getClassLoader(getPluginId(request)).getResource(getRootPath()),
resourcePath);
final File file = IoUtil.url2file(res);
ContentStream stream;
if( file != null )
{
stream = new FileContentStream(file, filename, mimeType);
}
else
{
stream = new URLContentStream(res, filename, mimeType);
}
contentStreamWriter.outputStream(request, response, stream);
}
示例2: add
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
private URL add(final String uid, final URL sourceUrl, final File file, final Date modified) throws IOException
{
URL result = IoUtil.file2url(file);
metaData.setProperty("uid:" + uid, uid);
String source = ShadingUtil.getRelativeUrl(shadowFolder, sourceUrl);
if( log.isDebugEnabled() )
{
log.debug("relativize: base=" + shadowFolder + "; url=" + sourceUrl + "; result=" + source);
}
metaData.setProperty(SOURCE + uid, source);
metaData.setProperty(FILE + uid, file.getName());
metaData.setProperty(MODIFIED + uid, dtf.format(modified));
save();
if( log.isDebugEnabled() )
{
log.debug("shading done, UID=" + uid + ", source=" + source + ", file=" + result + ", modified="
+ dtf.format(modified));
}
return result;
}
示例3: getManifestURL
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
private URL getManifestURL(final File file) throws MalformedURLException {
if(file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) {
URL url = new URL("jar:" + IoUtil.file2url(file).toExternalForm()
+ "!/plugin.xml");
if (IoUtil.isResourceExists(url)) {
return url;
}
url = new URL("jar:" + IoUtil.file2url(file).toExternalForm()
+ "!/plugin-fragment.xml");
if (IoUtil.isResourceExists(url)) {
return url;
}
url = new URL("jar:" + IoUtil.file2url(file).toExternalForm()
+ "!/META-INF/plugin.xml");
if (IoUtil.isResourceExists(url)) {
return url;
}
url = new URL("jar:" + IoUtil.file2url(file).toExternalForm()
+ "!/META-INF/plugin-fragment.xml");
if (IoUtil.isResourceExists(url)) {
return url;
}
return null;
}
return IoUtil.file2url(file);
}
示例4: unpack
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
static void unpack(final InputStream strm, final File destFolder) throws IOException
{
ZipInputStream zipStrm = new ZipInputStream(strm);
ZipEntry entry = zipStrm.getNextEntry();
while( entry != null )
{
String name = entry.getName();
File entryFile = new File(destFolder.getCanonicalPath() + "/" + name);
if( name.endsWith("/") )
{
if( !entryFile.exists() && !entryFile.mkdirs() )
{
throw new IOException(FOLDER_ERROR + entryFile);
}
}
else
{
File folder = entryFile.getParentFile();
if( !folder.exists() && !folder.mkdirs() )
{
throw new IOException(FOLDER_ERROR + folder);
}
OutputStream out = new BufferedOutputStream(new FileOutputStream(entryFile, false));
try
{
IoUtil.copyStream(zipStrm, out, 1024);
}
finally
{
out.close();
}
}
entryFile.setLastModified(entry.getTime());
entry = zipStrm.getNextEntry();
}
}
示例5: deleteFile
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
static boolean deleteFile(final File file)
{
if( file.isDirectory() )
{
IoUtil.emptyFolder(file);
}
return file.delete();
}
示例6: ShadowDataController
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
private ShadowDataController(final File folder, final FileFilter filter) throws IOException
{
shadowFolder = folder;
fileFilter = filter;
shadowFolderUrl = IoUtil.file2url(folder);
File metaFile = new File(shadowFolder, META_FILE_NAME);
metaData = new Properties();
if( metaFile.isFile() )
{
try
{
InputStream in = new FileInputStream(metaFile);
try
{
metaData.load(in);
}
finally
{
in.close();
}
if( log.isDebugEnabled() )
{
log.debug("meta-data loaded from file " + metaFile);
}
}
catch( IOException ioe )
{
log.warn("failed loading meta-data from file " + metaFile, ioe);
}
}
}
示例7: getFileForJar
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
public File getFileForJar(String jarFile)
{
TLEPluginLocation location = getJarMap().get(jarFile);
if( location != null )
{
return IoUtil.url2file(location.getContextLocation());
}
return null;
}
示例8: getReportEngine
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private synchronized IReportEngine getReportEngine()
{
try
{
Level logLevel = LOGGER.isDebugEnabled() ? Level.FINE : Level.SEVERE;
if( reportEngine == null )
{
LOGGER.info("Loading Birt engine");
EngineConfig engineConfig = new EngineConfig();
if( configService.isDebuggingMode() )
{
engineConfig.setOSGiConfig(ImmutableMap.of("osgi.dev", "true"));
}
URL resource = pluginService.getClassLoader("org.eclipse.birt.osgi").getResource("birt/");
String birtHome = IoUtil.url2file(resource).getAbsolutePath();
engineConfig.setBIRTHome(birtHome);
HTMLRenderOption emitterConfig = new HTMLRenderOption();
HTMLServerImageHandler imageHandler = new HTMLServerImageHandler();
emitterConfig.setImageHandler(imageHandler);
engineConfig.getEmitterConfigs().put("html", emitterConfig);
// get log info from LOG4J
java.util.logging.Logger birtLogger = java.util.logging.Logger.getLogger("org.eclipse.birt");
if( birtLogger != null )
{
birtLogger.addHandler(new Log4JHandler());
}
// It was either use these extended classes or modify birt.
Platform.startup(engineConfig);
IReportEngineFactory factory = (IReportEngineFactory) Platform
.createFactoryObject(IReportEngineFactory.EXTENSION_REPORT_ENGINE_FACTORY);
if( factory == null )
{
throw new BirtException("Could not get report engine factory");
}
reportEngine = factory.createReportEngine(engineConfig);
reportEngine.changeLogLevel(logLevel);
}
return reportEngine;
}
catch( BirtException e )
{
Platform.shutdown();
LOGGER.error("Error with Birt", e);
throw new RuntimeApplicationException("Error loading reporting engine", e);
}
}
示例9: service
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException,
IOException
{
String path = request.getPathInfo();
if( path.startsWith("/") )
{
path = Utils.safeSubstring(path, 1);
}
final int i;
if( STANDARD.equals(path) )
{
i = 0;
}
else if( GALLERY_THUMBNAIL.equals(path) )
{
i = 1;
}
else
{
response.sendError(404);
return;
}
final String filename = PLACEHOLDERS[i];
final URL res = new URL(ThumbInProgressServlet.class.getClassLoader().getResource("web/images/"), filename);
final File file = IoUtil.url2file(res);
ContentStream stream;
if( file != null )
{
stream = new FileContentStream(file, filename, "image/jpeg");
}
else
{
stream = new URLContentStream(res, filename, "image/jpeg");
}
stream.setCacheControl("max-age=31556926");
contentStreamWriter.outputStream(request, response, stream);
}
示例10: getLastModified
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
static Date getLastModified(final URL url) throws IOException
{
long result = 0;
if( JAR.equalsIgnoreCase(url.getProtocol()) )
{
String urlStr = url.toExternalForm();
int p = urlStr.indexOf("!/");
if( p != -1 )
{
return getLastModified(new URL(urlStr.substring(4, p)));
}
}
File sourceFile = IoUtil.url2file(url);
if( sourceFile != null )
{
result = sourceFile.lastModified();
}
else
{
URLConnection cnn = url.openConnection();
try
{
cnn.setUseCaches(false);
// this should force using HTTP HEAD method
if( cnn instanceof HttpURLConnection )
{
((HttpURLConnection) cnn).setRequestMethod("HEAD");
}
result = cnn.getLastModified();
}
finally
{
try
{
cnn.getInputStream().close();
}
catch( Exception ioe )
{
// ignore
}
}
}
if( result == 0 )
{
throw new IOException("can't retrieve modification date for resource " + url);
}
// for some reason modification milliseconds for some files are unstable
Calendar cldr = Calendar.getInstance(Locale.ENGLISH);
cldr.setTime(new Date(result));
cldr.set(Calendar.MILLISECOND, 0);
return cldr.getTime();
}
示例11: initRegistry
import org.java.plugin.util.IoUtil; //导入依赖的package包/类
private void initRegistry(boolean usePathResolver) throws PluginParseException {
ObjectFactory objectFactory = ObjectFactory.newInstance();
_registry = objectFactory.createRegistry();
File[] manifestFiles = getIncludedFiles();
List<URL> manifestUrls = new LinkedList<URL>();
final Map<String, URL> foldersMap = new HashMap<String, URL>();
for (int i = 0; i < manifestFiles.length; i++) {
File manifestFile = manifestFiles[i];
try {
URL manifestUrl = getManifestURL(manifestFile);
if (manifestUrl == null) {
logger.debug("Skipped file: " + manifestFile);
continue;
}
manifestUrls.add(manifestUrl);
logger.debug("Added URL: " + manifestUrl);
if (usePathResolver) {
if ("jar".equals(manifestUrl.getProtocol())) {
foldersMap.put(manifestUrl.toExternalForm(),
IoUtil.file2url(manifestFile));
} else {
foldersMap.put(manifestUrl.toExternalForm(),
IoUtil.file2url(manifestFile.getParentFile()));
}
}
} catch (MalformedURLException mue) {
throw new PluginParseException("can't create URL for file "
+ manifestFile);
}
}
final Map<String, Identity> processedPlugins;
try {
processedPlugins = _registry.register(
manifestUrls.toArray(new URL[manifestUrls.size()]));
} catch (Exception e) {
throw new PluginParseException("can't register URLs");
}
logger.debug("Registry initialized, registered manifests: "
+ processedPlugins.size() + " of " + manifestUrls.size());
if (usePathResolver) {
_pathResolver = objectFactory.createPathResolver();
for (Entry<String, Identity> entry : processedPlugins.entrySet()) {
_pathResolver.registerContext(entry.getValue(),
foldersMap.get(entry.getKey()));
}
logger.debug("Path resolver initialized");
}
}