org.eclipse.jetty.util.IO类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.5k)|赞(0)|评价(0)|浏览(180)

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

IO介绍

[英]IO Utilities. Provides stream handling utilities in singleton Threadpool implementation accessed by static members.
[中]IO实用程序。在静态成员访问的singleton Threadpool实现中提供流处理实用程序。

代码示例

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

  1. /**
  2. * @param out the output stream to write to
  3. * @param start First byte to write
  4. * @param count Bytes to write or -1 for all of them.
  5. * @throws IOException if unable to copy the Resource to the output
  6. */
  7. public void writeTo(OutputStream out,long start,long count)
  8. throws IOException
  9. {
  10. try (InputStream in = getInputStream())
  11. {
  12. in.skip(start);
  13. if (count<0)
  14. IO.copy(in,out);
  15. else
  16. IO.copy(in,out,count);
  17. }
  18. }

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

  1. /**
  2. * closes a reader, and logs exceptions
  3. *
  4. * @param reader the reader to close
  5. */
  6. public static void close(Reader reader)
  7. {
  8. close((Closeable)reader);
  9. }

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

  1. /** Read input stream to string.
  2. * @param in the stream to read from (until EOF)
  3. * @return the String parsed from stream (default Charset)
  4. * @throws IOException if unable to read the stream (or handle the charset)
  5. */
  6. public static String toString(InputStream in)
  7. throws IOException
  8. {
  9. return toString(in,(Charset)null);
  10. }

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

  1. /** Copy files or directories
  2. * @param from the file to copy
  3. * @param to the destination to copy to
  4. * @throws IOException if unable to copy
  5. */
  6. public static void copy(File from,File to) throws IOException
  7. {
  8. if (from.isDirectory())
  9. copyDir(from,to);
  10. else
  11. copyFile(from,to);
  12. }

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

  1. @Override
  2. public void copyTo(File destination)
  3. throws IOException
  4. {
  5. if (isDirectory())
  6. {
  7. IO.copyDir(getFile(),destination);
  8. }
  9. else
  10. {
  11. if (destination.exists())
  12. throw new IllegalArgumentException(destination+" exists");
  13. IO.copy(getFile(),destination);
  14. }
  15. }

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

  1. if (web_app.isAlias())
  2. LOG.debug(web_app + " anti-aliased to " + web_app.getAlias());
  3. web_app = context.newResource(web_app.getAlias());
  4. if (LOG.isDebugEnabled())
  5. LOG.debug("Try webapp=" + web_app + ", exists=" + web_app.exists() + ", directory=" + web_app.isDirectory()+" file="+(web_app.getFile()));
  6. IO.delete(extractedWebAppDir);
  7. extractedWebAppDir.mkdir();
  8. LOG.debug("Extract " + web_app + " to " + extractedWebAppDir);
  9. IO.delete(extractedWebInfDir);
  10. extractedWebInfDir.mkdir();
  11. Resource web_inf_lib = web_inf.addPath("lib/");
  12. IO.delete(webInfLibDir);
  13. webInfLibDir.mkdir();
  14. IO.delete(webInfClassesDir);
  15. webInfClassesDir.mkdir();
  16. LOG.debug("Copying WEB-INF/classes from "+web_inf_classes+" to "+webInfClassesDir.getAbsolutePath());

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

  1. public DefaultHandler()
  2. {
  3. try
  4. {
  5. URL fav = this.getClass().getClassLoader().getResource("org/eclipse/jetty/favicon.ico");
  6. if (fav!=null)
  7. {
  8. Resource r = Resource.newResource(fav);
  9. _favicon=IO.readBytes(r.getInputStream());
  10. }
  11. }
  12. catch(Exception e)
  13. {
  14. LOG.warn(e);
  15. }
  16. }

代码示例来源:origin: org.eclipse.jetty.aggregate/jetty-all-server

  1. public void destroy()
  2. {
  3. for (File file : _files)
  4. {
  5. if (file.exists())
  6. {
  7. LOG.debug("Destroy {}",file);
  8. IO.delete(file);
  9. }
  10. }
  11. }

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

  1. @Override
  2. public void destroy()
  3. {
  4. for (File file : _files)
  5. {
  6. if (file.exists())
  7. {
  8. if (LOG.isDebugEnabled())
  9. LOG.debug("Destroy {}",file);
  10. IO.delete(file);
  11. }
  12. }
  13. }

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

  1. byte[] bytes = IO.readBytes(content);
  2. if (LOG.isDebugEnabled())
  3. LOG.debug("foundClass({}) url={} cl={}",name,url,this);

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

  1. return;
  2. if(LOG.isDebugEnabled())
  3. LOG.debug("Extract "+this+" to "+directory);
  4. boolean subEntryIsDir = (subEntryName != null && subEntryName.endsWith("/")?true:false);
  5. if (LOG.isDebugEnabled())
  6. LOG.debug("Extracting entry = "+subEntryName+" from jar "+jarFileURL);
  7. URLConnection c = jarFileURL.openConnection();
  8. IO.copy(jin,fout);

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

  1. private Path extractPackedFile(JarFileResource configResource) throws IOException
  2. {
  3. String uri = configResource.getURI().toASCIIString();
  4. int colon = uri.lastIndexOf(":");
  5. int bang_slash = uri.indexOf("!/");
  6. if (colon < 0 || bang_slash < 0 || colon > bang_slash)
  7. throw new IllegalArgumentException("Not resolved JarFile resource: " + uri);
  8. String entry_path = uri.substring(colon + 2).replace("!/", "__").replace('/', '_').replace('.', '_');
  9. Path tmpDirectory = Files.createTempDirectory("users_store");
  10. tmpDirectory.toFile().deleteOnExit();
  11. Path extractedPath = Paths.get(tmpDirectory.toString(), entry_path);
  12. Files.deleteIfExists(extractedPath);
  13. extractedPath.toFile().deleteOnExit();
  14. IO.copy(configResource.getInputStream(), new FileOutputStream(extractedPath.toFile()));
  15. if (isHotReload())
  16. {
  17. LOG.warn("Cannot hot reload from packed configuration: {}", configResource);
  18. setHotReload(false);
  19. }
  20. return extractedPath;
  21. }

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

  1. @Override
  2. public void run()
  3. {
  4. try {
  5. if (in!=null)
  6. copy(in,out,-1);
  7. else
  8. copy(read,write,-1);
  9. }
  10. catch(IOException e)
  11. {
  12. LOG.ignore(e);
  13. try{
  14. if (out!=null)
  15. out.close();
  16. if (write!=null)
  17. write.close();
  18. }
  19. catch(IOException e2)
  20. {
  21. LOG.ignore(e2);
  22. }
  23. }
  24. }
  25. }

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

  1. /** Copy Reader to Writer out until EOF or exception.
  2. * @param in the read to read from (until EOF)
  3. * @param out the writer to write to
  4. * @throws IOException if unable to copy the streams
  5. */
  6. public static void copy(Reader in, Writer out)
  7. throws IOException
  8. {
  9. copy(in,out,-1);
  10. }

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

  1. @Override
  2. public void close() throws IOException {this.in=IO.getClosedStream();}
  3. };

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

  1. @Override
  2. public PrintWriter getWriter() throws IOException
  3. {
  4. return IO.getNullPrintWriter();
  5. }

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

  1. @Override
  2. public void deconfigure(WebAppContext context) throws Exception
  3. {
  4. //if we're not persisting the temp dir contents delete it
  5. if (!context.isPersistTempDirectory())
  6. {
  7. IO.delete(context.getTempDirectory());
  8. }
  9. //if it wasn't explicitly configured by the user, then unset it
  10. Boolean tmpdirConfigured = (Boolean)context.getAttribute(TEMPDIR_CONFIGURED);
  11. if (tmpdirConfigured != null && !tmpdirConfigured)
  12. context.setTempDirectory(null);
  13. //reset the base resource back to what it was before we did any unpacking of resources
  14. if (context.getBaseResource() != null)
  15. context.getBaseResource().close();
  16. context.setBaseResource(_preUnpackBaseResource);
  17. }

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

  1. public void configureTempDirectory (File dir, WebAppContext context)
  2. {
  3. if (dir == null)
  4. throw new IllegalArgumentException("Null temp dir");
  5. //if dir exists and we don't want it persisted, delete it
  6. if (dir.exists() && !context.isPersistTempDirectory())
  7. {
  8. if (!IO.delete(dir))
  9. throw new IllegalStateException("Failed to delete temp dir "+dir);
  10. }
  11. //if it doesn't exist make it
  12. if (!dir.exists())
  13. dir.mkdirs();
  14. if (!context.isPersistTempDirectory())
  15. dir.deleteOnExit();
  16. //is it useable
  17. if (!dir.canWrite() || !dir.isDirectory())
  18. throw new IllegalStateException("Temp dir "+dir+" not useable: writeable="+dir.canWrite()+", dir="+dir.isDirectory());
  19. }

代码示例来源:origin: cd.connect.common/connect-runnable-war

  1. public InMemoryResource(InMemoryResource parent, InputStream stream, String fileName) {
  2. this.parent = parent;
  3. try {
  4. self = new ByteArray();
  5. if (stream != null) {
  6. self.bytes = IO.readBytes(stream);
  7. }
  8. } catch (IOException e) {
  9. throw new RuntimeException(String.format("Unable to read input stream for %s", fileName) );
  10. }
  11. this.fileName = fileName;
  12. }

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

  1. @Override
  2. public void copyTo(File destination) throws IOException
  3. {
  4. if (isDirectory())
  5. {
  6. IO.copyDir(this.path.toFile(),destination);
  7. }
  8. else
  9. {
  10. Files.copy(this.path,destination.toPath());
  11. }
  12. }

相关文章