public SplFileInfo(Env env, StringValue fileName) { _path = env.lookupPwd(fileName); _parent = _path.getParent(); _fileName = _path.getTail(); }
@Override public String toString() { Path path = _path; if (path != null) return getClass().getSimpleName() + "[" + path.getTail() + "]"; else return getClass().getSimpleName() + "[" + path + "]"; }
public String getBasename(Env env, @Optional String suffix) { String name = _path.getTail(); if (suffix != null && name.endsWith(suffix)) { name = name.substring(0, name.length() - suffix.length()); } return name; }
public String getExtension(Env env) { String name = _path.getTail(); int pos = name.lastIndexOf('.'); if (0 <= pos && pos + 1 < name.length()) { return name.substring(pos + 1); } else { return ""; } }
private Templates generateFromNode(Node node, String systemId) throws IOException, TransformerConfigurationException { Path tempPath = writeTempFile(node); String tempId = tempPath.getTail(); StylesheetImpl stylesheet = loadPrecompiledStylesheet(tempId, tempId, false); if (systemId != null) tempPath.setUserPath(systemId); if (stylesheet != null) return stylesheet; return generate(node, tempPath); }
/** Initialize the log. */ public void init() throws IOException { long now = CurrentTime.getExactTime(); // server/0263 // _nextRolloverCheckTime = now + _rolloverCheckPeriod; Path path = getPath(); if (path != null) { path.getParent().mkdirs(); _rolloverPrefix = path.getTail(); long lastModified = path.getLastModified(); if (lastModified <= 0 || now < lastModified) { lastModified = now; } // _calendar.setGMTTime(lastModified); _nextPeriodEnd = nextRolloverTime(lastModified); } else { _nextPeriodEnd = nextRolloverTime(now); } if (_archiveFormat != null || getRolloverPeriod() <= 0) { } else if (_rolloverCron != null) _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H"; else if (getRolloverPeriod() % DAY == 0) _archiveFormat = _rolloverPrefix + ".%Y%m%d"; else if (getRolloverPeriod() % HOUR == 0) _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H"; else _archiveFormat = _rolloverPrefix + ".%Y%m%d.%H%M"; _isInit = true; _rolloverListener.requeue(_rolloverAlarm); rollover(); }
private void movePathToArchive(Path savedPath) { if (savedPath == null) return; synchronized (_logLock) { closeLogStream(); } Path path = getPath(); String savedName = savedPath.getTail(); try { if (!savedPath.getParent().isDirectory()) savedPath.getParent().mkdirs(); } catch (Exception e) { logWarning(L.l("Can't open archive directory {0}", savedPath.getParent()), e); } try { if (path.exists()) { WriteStream os = null; OutputStream out = null; // *.gz and *.zip are copied. Others are just renamed if (savedName.endsWith(".gz")) { os = savedPath.openWrite(); out = new GZIPOutputStream(os); } else if (savedName.endsWith(".zip")) { os = savedPath.openWrite(); ZipOutputStream zip = new ZipOutputStream(os); String entryName = savedName.substring(0, savedName.length() - 4); ZipEntry entry = new ZipEntry(entryName); zip.putNextEntry(entry); out = zip; } if (out != null) { try { path.writeToStream(out); } finally { try { out.close(); } catch (Exception e) { // can't log in log rotation routines } try { if (out != os) os.close(); } catch (Exception e) { // can't log in log rotation routines } } } else { path.renameTo(savedPath); } } } catch (Exception e) { logWarning(L.l("Error rotating logs: {0}", e.toString()), e); } try { path.remove(); /* try { if (! path.truncate()) path.remove(); } catch (IOException e) { path.remove(); throw e; } */ } catch (Exception e) { logWarning(L.l("Error truncating logs"), e); } if (_rolloverCount > 0) removeOldLogs(); }