Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (101)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (309)
Collections:
Other Resources:
JBrowser Source Code Files
JBrowser Source Code Files are provided in the source package file.
You can download JBrowser source package as described in the previous tutorial and go to the "src" sub-folder to view Source Code files.
You can also browse JBrowser Source Code files below:
✍: FYIcenter
⏎ org/mozilla/browser/impl/FileUtils.java
package org.mozilla.browser.impl; import java.io.BufferedInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; import java.net.URLDecoder; import java.util.zip.ZipEntry; import java.util.zip.ZipOutputStream; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; public class FileUtils { static Log log = LogFactory.getLog(FileUtils.class); public static String replaceExtensionInFileName(String file_name, String in_ext, String out_ext) { int idx = file_name.lastIndexOf('.'); if (idx>=0 && (in_ext==null || file_name.substring(idx+1).equalsIgnoreCase(in_ext))) return file_name.substring(0, idx+1) + out_ext; else return file_name + "." + out_ext; //$NON-NLS-1$ } public static String joinPaths(String path1, String path2) { if (path1.endsWith(""+File.separatorChar)) //$NON-NLS-1$ return path1+path2; else return path1+File.separatorChar+path2; } public static String getFileName(String path) { int idx = path.lastIndexOf(File.separatorChar); return (idx>=0 ? path.substring(idx+1) : path); } public static void createZip(File f, OutputStream os) throws IOException { ZipOutputStream zos = new ZipOutputStream(os); zos.setMethod(ZipOutputStream.DEFLATED); recZip(zos, f, ""); //$NON-NLS-1$ zos.close(); } private static void recZip(ZipOutputStream zos, File zipBaseDir, String relPath) throws IOException { File f = new File(zipBaseDir, relPath); if (f.exists()) { if (f.isDirectory()) { //if dir is found, delete all children first String [] flist = f.list(); for (int i=0; i<flist.length; i++) { String childRelPath = relPath.length()>0? relPath+File.separator+flist[i]: flist[i]; recZip(zos, zipBaseDir, childRelPath); } } else { //ErrorDump.debug(FileUtils.class, "zipping: "+relPath); InputStream in = new BufferedInputStream(new FileInputStream(f)); //add zip entry to output stream. zos.putNextEntry(new ZipEntry(relPath)); //transfer bytes from the file to the ZIP file int len; byte[] buf = new byte[1024]; while ((len = in.read(buf)) > 0) { zos.write(buf, 0, len); } //complete the entry zos.closeEntry(); in.close(); } } } public static byte[] readFile(File f) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); FileInputStream fis = new FileInputStream(f); InputStream is = new BufferedInputStream(fis); int len; byte[] buf = new byte[1024]; while ((len=is.read(buf))!=-1) { bos.write(buf,0, len); } is.close(); fis.close(); return bos.toByteArray(); } public static byte[] readStream(InputStream is) { try { ByteArrayOutputStream bos = new ByteArrayOutputStream(); byte[] buf = new byte[1000]; int n; while ((n=is.read(buf, 0, buf.length))!=-1) { bos.write(buf, 0, n); } is.close(); return bos.toByteArray(); } catch (IOException e) { log.error("error reading stream", e); //$NON-NLS-1$ return new byte[0]; } } /** * Safely converts a 'file:...' URL into a File, * (correctly handles spaces in the URL) */ public static File toFile(URL url) { try { String path = URLDecoder.decode(url.getPath(), "UTF-8"); //$NON-NLS-1$ String proto = url.getProtocol(); return toFile(path, proto); } catch (UnsupportedEncodingException e) { //should not happen log.error("error converting url to filename", e); //$NON-NLS-1$ throw new RuntimeException(e); } } public static File toFile(URI uri) { try { String path = URLDecoder.decode(uri.getPath(), "UTF-8"); //$NON-NLS-1$ String proto = uri.getScheme(); return toFile(path, proto); } catch (UnsupportedEncodingException e) { //should not happen log.error("error converting uri to filename", e); //$NON-NLS-1$ throw new RuntimeException(e); } } public static File urlToFile(String uri) { try { if (uri.startsWith("file:")) { //$NON-NLS-1$ URL u = new URL(uri); return toFile(u); } else { return null; } } catch (MalformedURLException e) { log.error("malformed url", e); //$NON-NLS-1$ throw new RuntimeException(e); } } private static File toFile(String path, String proto) { if (File.separatorChar != '/') path = path.replace('/', File.separatorChar); //on win32 remove the leading '/' if (File.separatorChar == '\\' && proto!=null && proto.equals("file") && //$NON-NLS-1$ path.startsWith("\\")) //$NON-NLS-1$ { path = path.substring(1); } return new File(path); } }
⏎ org/mozilla/browser/impl/FileUtils.java
Or download all of them as a single archive file:
File name: jbrowser-1.9-fyi.zip File size: 625318 bytes Release date: 2022-11-10 Download
⇐ Download and Install JBrowser Source Package
2017-07-17, 8533👍, 1💬
Popular Posts:
ANTLR is a powerful parser generator for multiple programming languages including Java. ANTLR contai...
JRE 5 sunjce_provider.jar is the JAR file for JRE 5 Sun JCE Provider, which provides implementations...
What Is jaxb-api-2.1.6.jar? Java Architecture for XML Binding (JAXB) is a Java API that allows Java ...
What Is activation.jar? I heard it's related to JAF (JavaBeans Activation Framework) 1.1? The if you...
Provides support for the runtime platform, core utility methods and the extension registry. JAR File...