コード例 #1
0
ファイル: FileUtils.java プロジェクト: Sanjay-F/WheelView
 /**
  * 获取文件名(不包括扩展名)
  *
  * @param pathOrUrl the path or url
  * @return name exclude extension
  */
 public static String getNameExcludeExtension(String pathOrUrl) {
   try {
     String name = getName(pathOrUrl);
     return name.substring(0, name.lastIndexOf('.'));
   } catch (Exception e) {
     LogUtils.warn(e.toString());
     return "";
   }
 }
コード例 #2
0
ファイル: FileUtils.java プロジェクト: Sanjay-F/WheelView
 /**
  * Rename boolean.
  *
  * @param src the src
  * @param tar the tar
  * @return the boolean
  */
 public static boolean rename(File src, File tar) {
   try {
     LogUtils.debug(
         String.format("rename %s to %s", src.getAbsolutePath(), tar.getAbsolutePath()));
     return src.renameTo(tar);
   } catch (Exception e) {
     LogUtils.warn(e);
     return false;
   }
 }
コード例 #3
0
 /**
  * Creates a reader that pipes the input file through a XSLT-Script that updates the version to
  * the current.
  *
  * @throws IOException
  */
 public Reader getUpdateReader(final File file, final String xsltScript)
     throws FileNotFoundException, IOException {
   try {
     String updatedXml = transform(file, xsltScript);
     return new StringReader(updatedXml);
   } catch (final Exception ex) {
     final String message = ex.getMessage();
     UITools.errorMessage(TextUtils.format("update_failed", String.valueOf(message)));
     LogUtils.warn(ex);
     final InputStream input = new BufferedInputStream(new FileInputStream(file));
     return getActualReader(input);
   }
 }
コード例 #4
0
 public void run() {
   final TransformerFactory transFact = TransformerFactory.newInstance();
   InputStream xsltInputStream = null;
   InputStream input = null;
   try {
     xsltInputStream = new BufferedInputStream(updaterUrl.openStream());
     final Source xsltSource = new StreamSource(xsltInputStream);
     input = new BufferedInputStream(inputUrl.openStream());
     final CleaningInputStream cleanedInput = new CleaningInputStream(input);
     final Reader reader =
         new InputStreamReader(
             cleanedInput,
             cleanedInput.isUtf8() ? Charset.forName("UTF-8") : FileUtils.defaultCharset());
     final Transformer trans = transFact.newTransformer(xsltSource);
     trans.transform(new StreamSource(reader), result);
   } catch (final Exception ex) {
     LogUtils.warn(ex);
     thrownException = ex;
   } finally {
     FileUtils.silentlyClose(input, xsltInputStream);
   }
 }