/** * gets a file from server and copy it local * * @return FTPCLient * @throws PageException * @throws IOException */ private AFTPClient actionGetFile() throws PageException, IOException { required("remotefile", remotefile); required("localfile", localfile); AFTPClient client = getClient(); Resource local = ResourceUtil.toResourceExistingParent(pageContext, localfile); // new File(localfile); pageContext.getConfig().getSecurityManager().checkFileLocation(local); if (failifexists && local.exists()) throw new ApplicationException( "File [" + local + "] already exist, if you want to overwrite, set attribute failIfExists to false"); OutputStream fos = null; client.setFileType(getType(local)); boolean success = false; try { fos = IOUtil.toBufferedOutputStream(local.getOutputStream()); success = client.retrieveFile(remotefile, fos); } finally { IOUtil.closeEL(fos); if (!success) local.delete(); } writeCfftp(client); return client; }
public boolean accept(Resource res) { if (res.isDirectory()) return allowDir; // load content String str = null; try { str = IOUtil.toString(res, "UTF-8"); } catch (IOException e) { return false; } int index = str.indexOf(':'); if (index != -1) { long expires = Caster.toLongValue(str.substring(0, index), -1L); // check is for backward compatibility, old files have no expires date inside. they do ot // expire if (expires != -1) { if (expires < System.currentTimeMillis()) { return true; } str = str.substring(index + 1); return false; } } // old files not having a timestamp inside else if (res.lastModified() <= time) { return true; } return false; }
public static void include( PageContext pc, ServletRequest req, ServletResponse rsp, String relPath) throws ServletException, IOException { relPath = optimizeRelPath(pc, relPath); boolean inline = HttpServletResponseWrap.get(); // print.out(rsp+":"+pc.getResponse()); RequestDispatcher disp = getRequestDispatcher(pc, relPath); if (inline) { // RequestDispatcher disp = getRequestDispatcher(pc,relPath); disp.include(req, rsp); return; } try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); HttpServletResponseWrap hsrw = new HttpServletResponseWrap(pc.getHttpServletResponse(), baos); HttpServletResponseWrap.set(true); // RequestDispatcher disp = getRequestDispatcher(pc,relPath); disp.include(req, hsrw); if (!hsrw.isCommitted()) hsrw.flushBuffer(); pc.write(IOUtil.toString(baos.toByteArray(), ReqRspUtil.getCharacterEncoding(pc, hsrw))); } finally { HttpServletResponseWrap.release(); ThreadLocalPageContext.register(pc); } }
/** * translate a file resource to a buffered image * * @param res * @return * @throws IOException */ @Override public final BufferedImage toBufferedImage(Resource res, String format) throws IOException { InputStream is = null; try { return Sanselan.getBufferedImage(is = res.getInputStream()); } catch (ImageReadException e) { throw ExceptionUtil.toIOException(e); } finally { IOUtil.closeEL(is); } }
/** * copy a local file to server * * @return FTPClient * @throws IOException * @throws PageException */ private AFTPClient actionPutFile() throws IOException, PageException { required("remotefile", remotefile); required("localfile", localfile); AFTPClient client = getClient(); Resource local = ResourceUtil.toResourceExisting(pageContext, localfile); // new File(localfile); // if(failifexists && local.exists()) throw new ApplicationException("File ["+local+"] already // exist, if you want to overwrite, set attribute failIfExists to false"); InputStream is = null; try { is = IOUtil.toBufferedInputStream(local.getInputStream()); client.setFileType(getType(local)); client.storeFile(remotefile, is); } finally { IOUtil.closeEL(is); } writeCfftp(client); return client; }
public void releaseDatasourceConnection(DatasourceConnection dc, boolean closeIt) { if (dc == null) return; DCStack stack = getDCStack(dc.getDatasource(), dc.getUsername(), dc.getPassword()); synchronized (stack) { if (closeIt) IOUtil.closeEL(dc.getConnection()); else stack.add(dc); int max = dc.getDatasource().getConnectionLimit(); if (max != -1) { _dec(dc.getDatasource()); stack.notify(); } else _dec(dc.getDatasource()); } }
private static Resource createAgentJar(Log log, Config c) throws IOException { Resource trg = getDeployDirectory(c).getRealResource("lucee-external-agent.jar"); if (!trg.exists() || trg.length() == 0) { log.info("Instrumentation", "create " + trg); InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/lucee-external-agent.jar"); if (jar == null) { throw new IOException("could not load jar [/resource/lib/lucee-external-agent.jar]"); } IOUtil.copy(jar, trg, true); } return trg; }
private static void addAttachIfNecessary(Config config, Log log) { String srcName = null, trgName = null; String archBits = (SystemUtil.getJREArch() == SystemUtil.ARCH_64) ? "64" : "32"; // Windows if (SystemUtil.isWindows()) { trgName = "attach.dll"; srcName = "windows" + archBits + "/" + trgName; } // Linux else if (SystemUtil.isLinux()) { trgName = "libattach.so"; srcName = "linux" + archBits + "/" + trgName; } // Solaris else if (SystemUtil.isSolaris()) { trgName = "libattach.so"; srcName = "solaris" + archBits + "/" + trgName; } // Mac OSX else if (SystemUtil.isMacOSX()) { trgName = "libattach.dylib"; srcName = "macosx" + archBits + "/" + trgName; } if (srcName != null) { // create dll if necessary Resource binDir = getBinDirectory(config); Resource trg = binDir.getRealResource(trgName); if (!trg.exists() || trg.length() == 0) { log.info("Instrumentation", "deploy /resource/bin/" + srcName + " to " + trg); InputStream src = InfoImpl.class.getResourceAsStream("/resource/bin/" + srcName); try { IOUtil.copy(src, trg, true); } catch (IOException e) { log.log(Log.LEVEL_ERROR, "Instrumentation", e); } } // set directory to library path SystemUtil.addLibraryPathIfNoExist(binDir, log); } }
private static Resource createToolsJar(Config config) throws IOException { Resource dir = getDeployDirectory(config); String os = "bsd"; // used for Mac OS X if (SystemUtil.isWindows()) { os = "windows"; } else if (SystemUtil.isLinux()) { // not MacOSX os = "linux"; } else if (SystemUtil.isSolaris()) { os = "solaris"; } String name = "tools-" + os + "-" + TOOLS_VERSION + ".jar"; Resource trg = dir.getRealResource(name); if (!trg.exists() || trg.length() == 0) { InputStream jar = InfoImpl.class.getResourceAsStream("/resource/lib/" + name); IOUtil.copy(jar, trg, true); } return trg; }
public static String getClassName(Resource res) throws IOException { byte[] src = IOUtil.toBytes(res); ClassReader cr = new ClassReader(src); return cr.getClassName(); }