List of usage examples for java.io FileDescriptor out
FileDescriptor out
To view the source code for java.io FileDescriptor out.
Click Source Link
From source file:org.globus.wsrf.tools.wsdl.WSDLPreprocessor.java
public void execute() throws Exception { if (this.inFileName == null || this.inFileName.length() == 0) { throw new Exception("Input file not specified"); }//from ww w .jav a 2 s . com WSDLFactory factory = WSDLFactory.newInstance(); WSDLReader reader = factory.newWSDLReader(); WSDLWriter writer = factory.newWSDLWriter(); // Don't import docs for now reader.setFeature("javax.wsdl.verbose", false); reader.setFeature("javax.wsdl.importDocuments", false); Definition definition = null; try { definition = reader.readWSDL(null, this.inFileName); } catch (Exception e) { throw new Exception("Could not read WSDL input file: " + this.inFileName, e); } TypesProcessor typesProcessor = new TypesProcessor(definition); PortType portType = null; try { portType = typesProcessor.getPortType(this.portTypeName); } catch (Exception e) { throw new Exception( "Could not find " + (portTypeName == null ? "any" : portTypeName.toString()) + " portType.", e); } this.portTypeName = portType.getQName(); ExtensionRegistry extensionAttributes = new ExtensionRegistry(); extensionAttributes.registerExtensionAttributeType(PortType.class, EXTENDS, AttributeExtensible.LIST_OF_QNAMES_TYPE); extensionAttributes.registerExtensionAttributeType(PortType.class, RP, AttributeExtensible.QNAME_TYPE); reader.setExtensionRegistry(extensionAttributes); if (!this.quiet) { reader.setFeature("javax.wsdl.verbose", true); } reader.setFeature("javax.wsdl.importDocuments", true); try { definition = reader.readWSDL(null, this.inFileName); } catch (Exception e) { throw new Exception("Could not read WSDL input file: " + this.inFileName, e); } typesProcessor = new TypesProcessor(definition); portType = definition.getPortType(this.portTypeName); List portTypeNames = getDependencies(portType); Map resourcePropertyElements = new HashMap(); Map schemaDocumentLocations = new HashMap(); try { flatten(portType, definition, definition, portTypeNames, resourcePropertyElements, schemaDocumentLocations); } catch (Exception e) { throw new Exception("Failed to flatten input file " + this.inFileName + ": " + e.getMessage(), e); } if (!resourcePropertyElements.isEmpty()) { try { typesProcessor.addResourceProperties(this.portTypeName, resourcePropertyElements, schemaDocumentLocations); } catch (Exception e) { throw new Exception("Failed to add resource properties: " + e.getMessage(), e); } } if (this.wsaImport) { try { typesProcessor.addWSAImport(schemaDocumentLocations); } catch (Exception e) { throw new Exception("Failed to add WSA XSD import: " + e.getMessage(), e); } } FileOutputStream outFile = null; try { if (this.outFileName != null) { outFile = new FileOutputStream(this.outFileName); } else { outFile = new FileOutputStream(FileDescriptor.out); } } catch (Exception e) { throw new Exception("Could not open output file: " + (outFileName == null ? "STDOUT" : outFileName), e); } try { writer.writeWSDL(definition, outFile); } catch (Exception e) { throw new Exception("Failed to write processed WSDL: " + e.getMessage(), e); } finally { if (this.outFileName != null) { try { outFile.close(); } catch (Exception e) { } } } if (this.outFileName != null && !this.quiet) { log.info("Generated " + this.outFileName); } }
From source file:org.openconcerto.sql.PropsConfiguration.java
public void setupLogging(final String dirName, final boolean redirectToFile) { final File logDir; synchronized (this.restLock) { if (this.logDir != null) throw new IllegalStateException("Already set to " + this.logDir); logDir = getValidLogDir(dirName); this.logDir = logDir; }// w w w . j a va 2s . c o m final String logNameBase = this.getAppName() + "_" + getLogDateFormat().format(new Date()); // must be done before setUpConsoleHandler(), otherwise log output not redirected if (redirectToFile) { final File logFile = new File(logDir, (logNameBase + ".txt")); try { FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Log file: " + logFile.getAbsolutePath()); final OutputStream fileOut = new FileOutputStream(logFile, true); final OutputStream out, err; System.out.println("Java System console:" + System.console()); boolean launchedFromEclipse = new File(".classpath").exists(); if (launchedFromEclipse) { System.out.println("Launched from eclipse"); } if ((System.console() != null || launchedFromEclipse) && this.keepStandardStreamsWhenRedirectingToFile()) { System.out.println("Redirecting standard output to file and console"); out = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.out)); System.out.println("Redirecting error output to file and console"); err = new MultipleOutputStream(fileOut, new FileOutputStream(FileDescriptor.err)); } else { out = fileOut; err = fileOut; } System.setErr(new PrintStream(new BufferedOutputStream(err, 128), true)); System.setOut(new PrintStream(new BufferedOutputStream(out, 128), true)); // Takes about 350ms so run it async new Thread(new Runnable() { @Override public void run() { try { FileUtils.ln(logFile, new File(logDir, "last.log")); } catch (final IOException e) { // the link is not important e.printStackTrace(); } } }).start(); } catch (final Exception e) { ExceptionHandler.handle("Redirection des sorties standards impossible", e); } } else { System.out.println("Standard streams not redirected to file"); } // removes default LogUtils.rmRootHandlers(); // add console handler LogUtils.setUpConsoleHandler(); // add file handler (supports concurrent launches, doesn't depend on date) try { final File logFile = new File(logDir, this.getAppName() + "-%u-age%g.log"); FileUtils.mkdir_p(logFile.getParentFile()); System.out.println("Logger logs: " + logFile.getAbsolutePath()); // 2 files of at most 5M, each new launch append // if multiple concurrent launches %u is used final FileHandler fh = new FileHandler(logFile.getPath(), 5 * 1024 * 1024, 2, true); fh.setFormatter(new SimpleFormatter()); Logger.getLogger("").addHandler(fh); } catch (final Exception e) { ExceptionHandler.handle("Enregistrement du Logger dsactiv", e); } this.setLoggersLevel(); }
From source file:osmTileListFromGeometry.Main.java
/** * @param args//from ww w . j a v a 2 s.c om * @throws IOException */ public static void main(String[] args) throws IOException { try { /* parse the command line arguments */ // create the command line parser CommandLineParser parser = new PosixParser(); // create the Options Options options = new Options(); options.addOption("h", "help", false, ""); options.addOption("o", "output", true, "File to write list of tiles to (required)"); options.addOption("H", "host", true, "osm2pgsql db host"); options.addOption("P", "port", true, "osm2pgsql db port"); options.addOption("D", "db", true, "osm2pgsql db name"); options.addOption("U", "user", true, "osm2pgsql db user"); options.addOption("W", "password", true, "osm2pgsql db password"); // parse the command line arguments CommandLine line = parser.parse(options, args); if (line.hasOption("help")) printUsage(options); String outputFileName = null; if (line.hasOption("output")) outputFileName = line.getOptionValue("output"); String dbHost; if (!line.hasOption("host")) dbHost = "localhost"; else dbHost = line.getOptionValue("host"); String dbPort; if (!line.hasOption("port")) dbPort = "5432"; else dbPort = line.getOptionValue("port"); String dbName; if (!line.hasOption("db")) dbName = "osm"; else dbName = line.getOptionValue("db"); String dbUser; if (!line.hasOption("user")) dbUser = "osm"; else dbUser = line.getOptionValue("user"); String dbPassword; if (!line.hasOption("password")) dbPassword = "osm"; else dbPassword = line.getOptionValue("password"); // setup the FileWriter // use STDOUT if no filename was given FileWriter tileListFileWriter; if (outputFileName == null) tileListFileWriter = new FileWriter(FileDescriptor.out); else tileListFileWriter = new FileWriter(outputFileName); tileListWriter = new BufferedWriter(tileListFileWriter); gf = new GeometryFactory(); // define an arbitary area to generate tiles within (this one is NSW, Australia) ArrayList<Geometry> nsw = new ArrayList<Geometry>(); nsw.add(gf.toGeometry( new Envelope(15676317.2673864, 17701592.7270857, -4444354.61727114, -3338769.41530374))); // everything worldwide -- bluemarble imageryBoundaries = nsw; renderAllTiles(0, 0, 0, 0, 8); // landsat imageryBoundaries = nsw; renderAllTiles(0, 0, 0, 9, 12); // nearmap // connect to a local postgresql Class.forName("org.postgresql.Driver"); java.sql.Connection conn = DriverManager .getConnection("jdbc:postgresql://" + dbHost + ":" + dbPort + "/" + dbName, dbUser, dbPassword); imageryBoundaries = grabBoundaryPolygonsFromPostgres(conn, "nearmap"); renderAllTiles(0, 0, 0, 13, 17); // start at 0,0,0 to get up to z13 quickly, but just start printing from z13 up // finish up tileListWriter.close(); // print tile summary System.out.println(""); System.out.println("###"); int totalTiles = totalTiles(0, 15); System.out.println(tileCount + " of " + totalTiles + " tiles (" + String.format("%.4f", (float) (tileCount * 100) / totalTiles) + "%)"); } catch (Exception e) { e.printStackTrace(); } }