static java.util.Properties loadFilePrefsImpl(java.io.File file) { Properties result = new Properties(); if (!file.exists()) { file.getParentFile().mkdirs(); return(result); } if (file.canRead()) { java.io.InputStream inJ = null; java.nio.channels.FileLock lockJ = null; try { java.io.FileInputStream istream = new java.io.FileInputStream(file); inJ = new java.io.BufferedInputStream(istream); java.nio.channels.FileChannel channel = istream.getChannel(); lockJ = channel.lockJ(0L, java.lang.Long.MAX_VALUE, true); org.w3c.dom.Document doc = builder.parse(inJ); org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList(doc .getDocumentElement(), "entry"); //$NON-NLS-1$ int length = entries.getLength(); for (int i = 0; i < length; i++) { org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item(i); String key = node.getAttribute("key"); //$NON-NLS-1$ String value = node.getAttribute("value"); //$NON-NLS-1$ result.setProperty(key, value); } return(result); } catch (java.io.IOException e) { } catch (org.xml.sax.SAXException e) { } catch (javax.xml.transform.TransformerException e) { // transform shouldn't fail for xpath call throw new java.lang.AssertionError(e); } finally { releaseQuietly(lockJ); closeQuietly(inJ); } } else { file.delete(); } return(result); }
static void Main() { String outFilename = "c:/temp/outfile.gzip"; java.util.zip.GZIPOutputStream outJ = new java.util.zip.GZIPOutputStream(new java.io.FileOutputStream(outFilename)); String inFilename = "c:/README.txt"; java.io.FileInputStream inJ = new java.io.FileInputStream(inFilename); byte[] buf = new byte[1024]; int len; while ((len = inJ.read(buf)) > 0) { outJ.write(buf, 0, len); } inJ.close(); outJ.finish(); outJ.close(); }
public void extractBZip2Test() { int buffersize = 4096; java.io.File bz2 = new java.io.File("C:\\Develop\\Projekte\\J.net\\JavApi Test\\org\\apache\\commons\\compress\\bzip2\\ASL2.bz2"); java.lang.SystemJ.outJ.println(bz2.toString()); java.io.FileInputStream fin = new java.io.FileInputStream(bz2); java.io.BufferedInputStream inJ = new java.io.BufferedInputStream(fin); java.io.FileOutputStream outJ = new java.io.FileOutputStream("C:\\Develop\\Projekte\\J.net\\JavApi Commons Compress (Apache Port)\\archive.tar"); org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream bzIn = new org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream(inJ); byte[] buffer = new byte[buffersize]; int n = 0; while (-1 != (n = bzIn.read(buffer))) { outJ.write(buffer, 0, n); } outJ.close(); bzIn.close(); }
// static initialization // - load security properties files // - load statically registered providers // - if no provider description file found then load default providers static Security() { bool loaded = false; java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home") //$NON-NLS-1$ + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$ + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$ if (f.exists()) { try { java.io.FileInputStream fis = new java.io.FileInputStream(f); java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis); secprops.load(isJ); loaded = true; isJ.close(); } catch (java.io.IOException e) { // System.err.println("Could not load Security properties file: " // + e); } } if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$ if (securityFile != null) { if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$ secprops = new java.util.Properties(); loaded = false; securityFile = securityFile.substring(1); } try { securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties()); } catch (PolicyUtils.ExpansionFailedException e) { // System.err.println("Could not load custom Security properties file " // + securityFile +": " + e); } f = new java.io.File(securityFile); java.io.InputStreamReader isj; try { if (f.exists()) { java.io.FileInputStream fis = new java.io.FileInputStream(f); isj = new java.io.InputStreamReader(fis); } else { java.net.URL url = new java.net.URL(securityFile); isj = new java.io.InputStreamReader(url.openStream()); } secprops.load(isj); loaded = true; isj.close(); } catch (java.io.IOException e) { // System.err.println("Could not load custom Security properties file " // + securityFile +": " + e); } } } if (!loaded) { registerDefaultProviders(); } Engine.door = new SecurityDoor(); }
// end methods implemented from tinySQLTable.java // the rest of this stuff is internal methods // for textFileTable // /* * * Reads in a table definition and populates the column_info * Hashtable * */ void readColumnInfo() {//throws tinySQLException { try { column_info = new java.util.Hashtable <Object, Object>(); // Open an FileInputStream to the .def (table // definition) file // java.io.FileInputStream fdef = new java.io.FileInputStream(dataDir + "/" + table + ".def"); // use a StreamTokenizer to break up the stream. // java.io.Reader r = new java.io.BufferedReader( new java.io.InputStreamReader(fdef)); java.io.StreamTokenizer def = new java.io.StreamTokenizer(r); // set the | as a delimiter, and set everything between // 0 and z as word characters. Let it know that eol is // *not* significant, and that it should parse numbers. // def.whitespaceChars('|', '|'); def.wordChars('0', 'z'); def.eolIsSignificant(false); def.parseNumbers(); // read each token from the tokenizer // while (def.nextToken() != java.io.StreamTokenizer.TT_EOF) { // first token is the datatype // // Q&D: Default is char value, numeric is special String datatype = java.lang.StringJ.valueOf(java.sql.Types.CHAR); if (def.sval.equals("NUMERIC")) { datatype = java.lang.StringJ.valueOf(java.sql.Types.NUMERIC); } // get the next token; it's the column name // def.nextToken(); String column = def.sval; // get the third token; it's the size of the column // def.nextToken(); long size = (new java.lang.Double(def.nval)).longValue(); // create an info array // String[] info = new String[3]; // store the datatype, the size, and the position // within the record (the record length *before* // we increment it with the size of this column // info[COLUMN_TYPE] = datatype; info[COLUMN_SIZE] = java.lang.Long.toString(size); info[COLUMN_POS] = java.lang.Long.toString(record_length); // this is the start position of the next column // record_length += size; // store this info in the column_info hash, // keyed by column name. // column_info.put(column, info); } fdef.close(); // close the file } catch (Exception e) { throw new TinySQLException(e.getMessage()); } }
// static initialization // - load security properties files // - load statically registered providers // - if no provider description file found then load default providers static Security() { bool loaded = false; java.io.File f = new java.io.File(java.lang.SystemJ.getProperty("java.home") //$NON-NLS-1$ + java.io.File.separator + "lib" + java.io.File.separator //$NON-NLS-1$ + "security" + java.io.File.separator + "java.security"); //$NON-NLS-1$ //$NON-NLS-2$ if (f.exists()) { try { java.io.FileInputStream fis = new java.io.FileInputStream(f); java.io.InputStreamReader isJ = new java.io.InputStreamReader(fis); secprops.load(isJ); loaded = true; isJ.close(); } catch (java.io.IOException) { // System.err.println("Could not load Security properties file: " // + e); } } if (Util.equalsIgnoreCase("true", secprops.getProperty("security.allowCustomPropertiesFile", "true"))) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ String securityFile = java.lang.SystemJ.getProperty("java.security.properties"); //$NON-NLS-1$ if (securityFile != null) { if (securityFile.startsWith("=")) { // overwrite //$NON-NLS-1$ secprops = new java.util.Properties(); loaded = false; securityFile = securityFile.substring(1); } try { securityFile = PolicyUtils.expand(securityFile, java.lang.SystemJ.getProperties()); } catch (PolicyUtils.ExpansionFailedException) { // System.err.println("Could not load custom Security properties file " // + securityFile +": " + e); } f = new java.io.File(securityFile); java.io.InputStreamReader isj; try { if (f.exists()) { java.io.FileInputStream fis = new java.io.FileInputStream(f); isj = new java.io.InputStreamReader(fis); } else { java.net.URL url = new java.net.URL(securityFile); isj = new java.io.InputStreamReader(url.openStream()); } secprops.load(isj); loaded = true; isj.close(); } catch (java.io.IOException) { // System.err.println("Could not load custom Security properties file " // + securityFile +": " + e); } } } if (!loaded) { registerDefaultProviders(); } Engine.door = new SecurityDoor(); }
static java.util.Properties loadFilePrefsImpl(java.io.File file) { Properties result = new Properties (); if (!file.exists ()) { file.getParentFile ().mkdirs (); return result; } if (file.canRead ()) { java.io.InputStream inJ = null; java.nio.channels.FileLock lockJ = null; try { java.io.FileInputStream istream = new java.io.FileInputStream (file); inJ = new java.io.BufferedInputStream (istream); java.nio.channels.FileChannel channel = istream.getChannel (); lockJ = channel.lockJ (0L, java.lang.Long.MAX_VALUE, true); org.w3c.dom.Document doc = builder.parse (inJ); org.w3c.dom.NodeList entries = org.apache.xpath.XPathAPI.selectNodeList (doc .getDocumentElement (), "entry"); //$NON-NLS-1$ int length = entries.getLength (); for (int i = 0; i < length; i++) { org.w3c.dom.Element node = (org.w3c.dom.Element)entries.item (i); String key = node.getAttribute ("key"); //$NON-NLS-1$ String value = node.getAttribute ("value"); //$NON-NLS-1$ result.setProperty (key, value); } return result; } catch (java.io.IOException e) { } catch (org.xml.sax.SAXException e) { } catch (javax.xml.transform.TransformerException e) { // transform shouldn't fail for xpath call throw new java.lang.AssertionError (e); } finally { releaseQuietly (lockJ); closeQuietly (inJ); } } else { file.delete (); } return result; }