org.eclipse.jetty.webapp.WebAppContext.isPersistTempDirectory()方法的使用及代码示例

x33g5p2x  于2022-02-02 转载在 其他  
字(5.9k)|赞(0)|评价(0)|浏览(119)

本文整理了Java中org.eclipse.jetty.webapp.WebAppContext.isPersistTempDirectory()方法的一些代码示例,展示了WebAppContext.isPersistTempDirectory()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。WebAppContext.isPersistTempDirectory()方法的具体详情如下:
包路径:org.eclipse.jetty.webapp.WebAppContext
类名称:WebAppContext
方法名:isPersistTempDirectory

WebAppContext.isPersistTempDirectory介绍

暂无

代码示例

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

public void configureTempDirectory (File dir, WebAppContext context)
{
  if (dir == null)
    throw new IllegalArgumentException("Null temp dir");
  //if dir exists and we don't want it persisted, delete it
  if (dir.exists() && !context.isPersistTempDirectory())
  {
    if (!IO.delete(dir))
      throw new IllegalStateException("Failed to delete temp dir "+dir);
  }
  //if it doesn't exist make it
  if (!dir.exists())
    dir.mkdirs();
  if (!context.isPersistTempDirectory())
    dir.deleteOnExit();
  //is it useable
  if (!dir.canWrite() || !dir.isDirectory())   
    throw new IllegalStateException("Temp dir "+dir+" not useable: writeable="+dir.canWrite()+", dir="+dir.isDirectory());
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

public void makeTempDirectory (File parent, WebAppContext context)
    throws Exception
{
  if (parent == null || !parent.exists() || !parent.canWrite() || !parent.isDirectory())
    throw new IllegalStateException("Parent for temp dir not configured correctly: "+(parent==null?"null":"writeable="+parent.canWrite()));
  //Create a name for the webapp     
  String temp = getCanonicalNameForWebAppTmpDir(context);
  File tmpDir = null;
  if (context.isPersistTempDirectory())
  {
    //if it is to be persisted, make sure it will be the same name
    //by not using File.createTempFile, which appends random digits
    tmpDir = new File (parent, temp);
  }
  else
  {
    //ensure file will always be unique by appending random digits
    tmpDir = File.createTempFile(temp, ".dir", parent);
    //delete the file that was created
    tmpDir.delete();
    //and make a directory of the same name
    tmpDir.mkdirs();
  }
  configureTempDirectory(tmpDir, context);
  if(LOG.isDebugEnabled())
    LOG.debug("Set temp dir "+tmpDir);
  context.setTempDirectory(tmpDir);
}

代码示例来源:origin: org.eclipse.jetty/jetty-webapp

@Override
public void deconfigure(WebAppContext context) throws Exception
{
  //if we're not persisting the temp dir contents delete it
  if (!context.isPersistTempDirectory())
  {
    IO.delete(context.getTempDirectory());
  }
  
  //if it wasn't explicitly configured by the user, then unset it
  Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED);
  if (tmpdirConfigured != null && !tmpdirConfigured) 
    context.setTempDirectory(null);
  //reset the base resource back to what it was before we did any unpacking of resources
  if (context.getBaseResource() != null)
    context.getBaseResource().close();
  context.setBaseResource(_preUnpackBaseResource);
}

代码示例来源:origin: jenkinsci/winstone

public void configureTempDirectory (File dir, WebAppContext context)
{
  if (dir == null)
    throw new IllegalArgumentException("Null temp dir");
  //if dir exists and we don't want it persisted, delete it
  if (dir.exists() && !context.isPersistTempDirectory())
  {
    if (!IO.delete(dir))
      throw new IllegalStateException("Failed to delete temp dir "+dir);
  }
  //if it doesn't exist make it
  if (!dir.exists())
    dir.mkdirs();
  if (!context.isPersistTempDirectory())
    dir.deleteOnExit();
  //is it useable
  if (!dir.canWrite() || !dir.isDirectory())   
    throw new IllegalStateException("Temp dir "+dir+" not useable: writeable="+dir.canWrite()+", dir="+dir.isDirectory());
}

代码示例来源:origin: apache/activemq-artemis

tmpdir = context.getTempDirectory();
if (tmpdir != null && tmpdir.exists() && !context.isPersistTempDirectory()) {

代码示例来源:origin: jenkinsci/winstone

public void makeTempDirectory (File parent, WebAppContext context)
    throws Exception
{
  if (parent == null || !parent.exists() || !parent.canWrite() || !parent.isDirectory())
    throw new IllegalStateException("Parent for temp dir not configured correctly: "+(parent==null?"null":"writeable="+parent.canWrite()));
  //Create a name for the webapp     
  String temp = getCanonicalNameForWebAppTmpDir(context);
  File tmpDir = null;
  if (context.isPersistTempDirectory())
  {
    //if it is to be persisted, make sure it will be the same name
    //by not using File.createTempFile, which appends random digits
    tmpDir = new File (parent, temp);
  }
  else
  {
    //ensure file will always be unique by appending random digits
    tmpDir = File.createTempFile(temp, ".dir", parent);
    //delete the file that was created
    tmpDir.delete();
    //and make a directory of the same name
    tmpDir.mkdirs();
  }
  configureTempDirectory(tmpDir, context);
  if(LOG.isDebugEnabled())
    LOG.debug("Set temp dir "+tmpDir);
  context.setTempDirectory(tmpDir);
}

代码示例来源:origin: org.apache.activemq/artemis-web

public void internalStop() throws Exception {
 server.stop();
 if (webContexts != null) {
   File tmpdir = null;
   for (WebAppContext context : webContexts) {
    tmpdir = context.getTempDirectory();
    if (tmpdir != null && !context.isPersistTempDirectory()) {
      //tmpdir will be removed by deleteOnExit()
      //somehow when broker is stopped and restarted quickly
      //this tmpdir won't get deleted sometimes
      boolean fileDeleted = TimeUtils.waitOnBoolean(false, 5000, tmpdir::exists);
      if (!fileDeleted) {
       //because the execution order of shutdown hooks are
       //not determined, so it's possible that the deleteOnExit
       //is executed after this hook, in that case we force a delete.
       FileUtil.deleteDirectory(tmpdir);
       logger.debug("Force to delete temporary file on shutdown: " + tmpdir.getAbsolutePath());
       if (tmpdir.exists()) {
         ActiveMQWebLogger.LOGGER.tmpFileNotDeleted(tmpdir);
       }
      }
    }
   }
   webContexts.clear();
 }
}

代码示例来源:origin: jenkinsci/winstone

@Override
public void deconfigure(WebAppContext context) throws Exception
{
  //if we're not persisting the temp dir contents delete it
  if (!context.isPersistTempDirectory())
  {
    IO.delete(context.getTempDirectory());
  }
  
  //if it wasn't explicitly configured by the user, then unset it
  Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED);
  if (tmpdirConfigured != null && !tmpdirConfigured) 
    context.setTempDirectory(null);
  //reset the base resource back to what it was before we did any unpacking of resources
  if (context.getBaseResource() != null)
    context.getBaseResource().close();
  context.setBaseResource(_preUnpackBaseResource);
}

相关文章

微信公众号

最新文章

更多

WebAppContext类方法