List of usage examples for java.io IOException getMessage
public String getMessage()
From source file:com.myjeeva.poi.ExcelWorkSheetHandlerTest.java
/** * @param args/*from ww w . jav a 2s. c om*/ * @throws Exception */ public static void main(String[] args) throws Exception { String SAMPLE_PERSON_DATA_FILE_PATH = "src/test/resources/Sample-Person-Data.xlsx"; // Input File initialize File file = new File(SAMPLE_PERSON_DATA_FILE_PATH); InputStream inputStream = new FileInputStream(file); // Excel Cell Mapping Map<String, String> cellMapping = new HashMap<String, String>(); cellMapping.put("HEADER", "Person Id,Name,Height,Email Address,DOB,Salary"); cellMapping.put("A", "personId"); cellMapping.put("B", "name"); cellMapping.put("C", "height"); cellMapping.put("D", "emailId"); cellMapping.put("E", "dob"); cellMapping.put("F", "salary"); // The package open is instantaneous, as it should be. OPCPackage pkg = null; try { ExcelWorkSheetHandler<PersonVO> workSheetHandler = new ExcelWorkSheetHandler<PersonVO>(PersonVO.class, cellMapping); pkg = OPCPackage.open(inputStream); ExcelSheetCallback sheetCallback = new ExcelSheetCallback() { private int sheetNumber = 0; @Override public void startSheet(int sheetNum, String sheetName) { this.sheetNumber = sheetNum; System.out.println("Started processing sheet number=" + sheetNumber + " and Sheet Name is '" + sheetName + "'"); } @Override public void endSheet() { System.out.println("Processing completed for sheet number=" + sheetNumber); } }; System.out.println("Constructor: pkg, workSheetHandler, sheetCallback"); ExcelReader example1 = new ExcelReader(pkg, workSheetHandler, sheetCallback); example1.process(); if (workSheetHandler.getValueList().isEmpty()) { // No data present LOG.error("sHandler.getValueList() is empty"); } else { LOG.info(workSheetHandler.getValueList().size() + " no. of records read from given excel worksheet successfully."); // Displaying data ead from Excel file displayPersonList(workSheetHandler.getValueList()); } System.out.println("\nConstructor: filePath, workSheetHandler, sheetCallback"); ExcelReader example2 = new ExcelReader(SAMPLE_PERSON_DATA_FILE_PATH, workSheetHandler, sheetCallback); example2.process(); System.out.println("\nConstructor: file, workSheetHandler, sheetCallback"); ExcelReader example3 = new ExcelReader(file, workSheetHandler, null); example3.process(); } catch (RuntimeException are) { LOG.error(are.getMessage(), are.getCause()); } catch (InvalidFormatException ife) { LOG.error(ife.getMessage(), ife.getCause()); } catch (IOException ioe) { LOG.error(ioe.getMessage(), ioe.getCause()); } finally { IOUtils.closeQuietly(inputStream); try { if (null != pkg) { pkg.close(); } } catch (IOException e) { // just ignore IO exception } } }
From source file:copi.ScalaEntryPoint.java
public static void main(String[] args) { /*//from ww w . j av a 2s . c om * Set lwjgl library path so that LWJGL finds the natives depending on * the OS. */ File libDir = new File(path); if (!libDir.exists()) { // create native lib folder libDir.mkdir(); // retrieve os type String osName = System.getProperty("os.name"); // try to determine if the system is 64 bit boolean is64bit = false; if (System.getProperty("os.name").contains("Windows")) { is64bit = (System.getenv("ProgramFiles(x86)") != null); } else { is64bit = (System.getProperty("os.arch").indexOf("64") != -1); } // construct name of native lib file String natLibLWJGL = ""; if (osName.startsWith("Windows")) { natLibLWJGL += "lwjgl"; if (is64bit) natLibLWJGL += "64"; natLibLWJGL += ".dll"; } else if (osName.startsWith("Linux")) { natLibLWJGL += "liblwjgl"; if (is64bit) natLibLWJGL += "64"; natLibLWJGL += ".so"; } else if (osName.startsWith("Mac OS X")) { natLibLWJGL += "liblwjgl"; natLibLWJGL += ".jnilib"; } else { System.out.println("Unsupported OS: " + osName + ". Exiting."); System.exit(-1); } // try to establish an input stream on the native lib inside the jar InputStream fis = ScalaEntryPoint.class.getResourceAsStream("/" + natLibLWJGL); if (fis == null) { System.out.println("Native library file " + natLibLWJGL + " was not found inside JAR."); System.exit(-1); } // establish an output stream on the target file File fOut = new File(path + "/" + natLibLWJGL); try (FileOutputStream fos = new FileOutputStream(fOut)) { // create file at destination if not already existing if (!fOut.exists()) fOut.createNewFile(); // making buffer for copy operation byte[] buffer = new byte[1024]; int readBytes; // Open output stream and copy data between source file in JAR and the temporary file try { while ((readBytes = fis.read(buffer)) != -1) { fos.write(buffer, 0, readBytes); } } finally { fos.close(); fis.close(); } } catch (IOException e) { System.out.println(e.getMessage()); System.exit(-1); } // register shutdown hook JVMShutdownHook jvmShutdownHook = new JVMShutdownHook(); Runtime.getRuntime().addShutdownHook(jvmShutdownHook); } // set lwjgl native library path System.setProperty("org.lwjgl.librarypath", libDir.getAbsolutePath()); // start COPI System.out.println("Starting COPI ..."); (new SICApplicationLogic()).render(); }
From source file:be.vdab.util.Programma.java
public static void main(String[] args) { SortedSet<Voertuig> voertuigen = new TreeSet<Voertuig>(); Datum datum = null;/*from w ww. j a v a 2s . c o m*/ Volume volumePickup = null; Volume volumeVrachtwagen = null; try { datum = new Datum(21, 11, 2012); } catch (DatumException de) { System.out.println(de.getMessage()); } Mens bestuurder_BC = new Mens("Albert", Rijbewijs.B, Rijbewijs.C); Mens inzittende_A = new Mens("Karolien", Rijbewijs.A); Mens inzittende = new Mens("Zora"); Mens inzittende_B = new Mens("David", Rijbewijs.B); Mens inzittende_DDE = new Mens("Evert", Rijbewijs.D, Rijbewijs.DE); Mens bestuurder_DE = new Mens("Boris", Rijbewijs.DE); Personenwagen wagen1Opel = new Personenwagen("Opel", datum, 250000, 4, Color.blue, bestuurder_BC, inzittende_A, inzittende); Personenwagen wagen2 = new Personenwagen("Mazda", datum, 27000, 5, Color.blue, bestuurder_BC, inzittende_A); try { volumePickup = new Volume(3, 3, 2, Maat.meter); volumeVrachtwagen = new Volume(3, 6, 2, Maat.meter); } catch (VolumeException ve) { System.out.println(ve.getMessage()); } Pickup pickup1Opel = new Pickup("Opel", datum, 400000, 5, Color.RED, volumePickup, bestuurder_BC, inzittende_B, inzittende_DDE, inzittende_A); Pickup pickup2 = new Pickup("Toyota", datum, 39000, 4, Color.blue, volumePickup, bestuurder_BC); Vrachtwagen vrachtwagen1 = new Vrachtwagen("BMW", datum, 90000, 2, volumeVrachtwagen, 3000, 6, bestuurder_BC, inzittende_A); Vrachtwagen vrachtwagen2 = new Vrachtwagen("Mercedes", datum, 120000, 3, volumeVrachtwagen, 2000, 8, bestuurder_BC, inzittende); voertuigen.add(wagen1Opel); //gesorteerd op nummerplaat voertuigen.add(wagen2); voertuigen.add(pickup1Opel); voertuigen.add(pickup2); voertuigen.add(vrachtwagen1); voertuigen.add(vrachtwagen2); print(voertuigen); /* //copy manier1 //copy (niet nodig dadelijk naar list omzetten, maar dan zit het niet in een SortedSet, oplossing: zelf copy uitvoeren, maar niet enkel referenties Set<Voertuig> voertuigen2=null;//=new TreeSet<Voertuig>(voertuigen); //new TreeSet<Voertuig>( org.apache.commons.collections.ComparatorUtils.reversedComparator( Voertuig.getAankoopprijsComparator())); //transformeren naar List, ook een copy List<Voertuig> lijst=new ArrayList<Voertuig>(voertuigen);//niet voertuigen 2 //sort Collections.sort(lijst, org.apache.commons.collections.ComparatorUtils.reversedComparator( Voertuig.getAankoopprijsComparator())); print(lijst); */ Set<Voertuig> voertuigen2 = new TreeSet<Voertuig>(org.apache.commons.collections.ComparatorUtils .reversedComparator(Voertuig.getAankoopprijsComparator())); voertuigen2.addAll(voertuigen); print(voertuigen2); //Copy manier 2: beter Set<Voertuig> voertuigen3 = new TreeSet<Voertuig>(Voertuig.getMerkComparator()); voertuigen3.addAll(voertuigen);//deep copy of niet , staat niet in de api. Maakt het uit hier? wanneer wel?als je de vrachtwagens gaat wijzigen en je wil dat die alleen in de copy gewijzigd zijn dan deep copy nodig print(voertuigen3); try { schrijweg((TreeSet) voertuigen3, "wagenpark.ser"); } catch (FileNotFoundException fnfe) { System.out.println(fnfe.getMessage()); } catch (IOException ioe) { System.out.println(ioe.getMessage()); } TreeSet<Voertuig> voertuigen4 = lees("wagenpark.ser"); System.out.println("Voertuigen4"); print(voertuigen4); }
From source file:edu.lternet.pasta.client.EmlUtility.java
/** * @param args String array with three arguments: * arg[0] absolute path to the input XML file * arg[1] absolute path to the output HTML file * arg[2] absolute path to the EML XSLT stylesheet */// w ww. j a va 2 s . c o m public static void main(String[] args) { String inputPath = args[0]; String outputPath = args[1]; String emlXslPath = args[2]; ConfigurationListener.configure(); File inFile = new File(inputPath); File outFile = new File(outputPath); String eml = null; try { eml = FileUtils.readFileToString(inFile); } catch (IOException e1) { logger.error(e1.getMessage()); e1.printStackTrace(); } EmlUtility eu = null; try { eu = new EmlUtility(eml); } catch (ParseException e) { logger.error(e.getMessage()); e.printStackTrace(); } String html = eu.xmlToHtml(emlXslPath, null); try { FileUtils.writeStringToFile(outFile, html); } catch (IOException e) { logger.error(e.getMessage()); e.printStackTrace(); } }
From source file:net.recommenders.plista.client.Client.java
/** * This method starts the server//ww w . j a v a2 s.co m * * @param args * @throws Exception */ public static void main(String[] args) throws Exception { final Properties properties = new Properties(); String fileName = ""; String recommenderClass = null; String handlerClass = null; if (args.length < 3) { fileName = System.getProperty("propertyFile"); } else { fileName = args[0]; recommenderClass = args[1]; handlerClass = args[2]; } // load the team properties try { properties.load(new FileInputStream(fileName)); } catch (IOException e) { logger.error(e.getMessage()); } catch (Exception e) { logger.error(e.getMessage()); } Recommender recommender = null; recommenderClass = (recommenderClass != null ? recommenderClass : properties.getProperty("plista.recommender")); System.out.println(recommenderClass); lognum = Integer.parseInt(properties.getProperty("plista.lognum")); try { final Class<?> transformClass = Class.forName(recommenderClass); recommender = (Recommender) transformClass.newInstance(); } catch (Exception e) { logger.error(e.getMessage()); throw new IllegalArgumentException("No recommender specified or recommender not available."); } // configure log4j /*if (args.length >= 4 && args[3] != null) { PropertyConfigurator.configure(args[0]); } else { PropertyConfigurator.configure("log4j.properties"); }*/ // set up and start server AbstractHandler handler = null; handlerClass = (handlerClass != null ? handlerClass : properties.getProperty("plista.handler")); System.out.println(handlerClass); try { final Class<?> transformClass = Class.forName(handlerClass); handler = (AbstractHandler) transformClass.getConstructor(Properties.class, Recommender.class) .newInstance(properties, recommender); } catch (Exception e) { logger.error(e.getMessage()); e.printStackTrace(); throw new IllegalArgumentException("No handler specified or handler not available."); } final Server server = new Server(Integer.parseInt(properties.getProperty("plista.port", "8080"))); server.setHandler(handler); logger.debug("Serverport " + server.getConnectors()[0].getPort()); server.start(); server.join(); }
From source file:com.yulore.demo.NHttpClient.java
public static void main(String[] args) throws Exception { // Create HTTP protocol processing chain HttpProcessor httpproc = HttpProcessorBuilder.create() // Use standard client-side protocol interceptors .add(new RequestContent()).add(new RequestTargetHost()).add(new RequestConnControl()) .add(new RequestUserAgent("Test/1.1")).add(new RequestExpectContinue(true)).build(); // Create client-side HTTP protocol handler HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor(); // Create client-side I/O event dispatch final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, ConnectionConfig.DEFAULT);/*from w w w . j a v a 2 s . c o m*/ // Create client-side I/O reactor final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(); // Create HTTP connection pool BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT); // Limit total number of connections to just two pool.setDefaultMaxPerRoute(2); pool.setMaxTotal(2); // Run the I/O reactor in a separate thread Thread t = new Thread(new Runnable() { public void run() { try { // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); } }); // Start the client thread t.start(); // Create HTTP requester HttpAsyncRequester requester = new HttpAsyncRequester(httpproc); // Execute HTTP GETs to the following hosts and HttpHost[] targets = new HttpHost[] { new HttpHost("www.apache.org", 80, "http"), new HttpHost("www.verisign.com", 443, "https"), new HttpHost("www.google.com", 80, "http") }; final CountDownLatch latch = new CountDownLatch(targets.length); for (final HttpHost target : targets) { BasicHttpRequest request = new BasicHttpRequest("GET", "/"); HttpCoreContext coreContext = HttpCoreContext.create(); requester.execute(new BasicAsyncRequestProducer(target, request), new BasicAsyncResponseConsumer(), pool, coreContext, // Handle HTTP response from a callback new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); System.out.println(target + "->" + response.getStatusLine()); } public void failed(final Exception ex) { latch.countDown(); System.out.println(target + "->" + ex); } public void cancelled() { latch.countDown(); System.out.println(target + " cancelled"); } }); } latch.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:com.mycompany.javaapplicaton3.ExcelWorkSheetHandlerTest.java
/** * @param args/*from w w w. ja va2s . c o m*/ * @throws Exception */ public static void main(String[] args) throws Exception { String SAMPLE_PERSON_DATA_FILE_PATH = "C:/Users/lprates/Documents/Sample-Person-Data.xlsx"; // Input File initialize File file = new File(SAMPLE_PERSON_DATA_FILE_PATH); InputStream inputStream = new FileInputStream(file); // Excel Cell Mapping Map<String, String> cellMapping = new HashMap<String, String>(); cellMapping.put("HEADER", "Person Id,Name,Height,Email Address,DOB,Salary"); cellMapping.put("A", "personId"); cellMapping.put("B", "name"); cellMapping.put("C", "height"); cellMapping.put("D", "emailId"); cellMapping.put("E", "dob"); cellMapping.put("F", "salary"); // The package open is instantaneous, as it should be. OPCPackage pkg = null; try { ExcelWorkSheetHandler<PersonVO> workSheetHandler = new ExcelWorkSheetHandler<PersonVO>(PersonVO.class, cellMapping); pkg = OPCPackage.open(inputStream); ExcelSheetCallback sheetCallback = new ExcelSheetCallback() { private int sheetNumber = 0; public void startSheet(int sheetNum, String sheetName) { this.sheetNumber = sheetNum; System.out.println("Started processing sheet number=" + sheetNumber + " and Sheet Name is '" + sheetName + "'"); } @Override public void endSheet() { System.out.println("Processing completed for sheet number=" + sheetNumber); } public void startSheet(int sheetNum) { System.out.println("Started processing sheet number=" + sheetNum); } }; System.out.println("Constructor: pkg, workSheetHandler, sheetCallback"); ExcelReader example1 = new ExcelReader(pkg, workSheetHandler, sheetCallback); example1.process("Lot 1 Data"); if (workSheetHandler.getValueList().isEmpty()) { // No data present LOG.error("sHandler.getValueList() is empty"); } else { LOG.info(workSheetHandler.getValueList().size() + " no. of records read from given excel worksheet successfully."); // Displaying data ead from Excel file displayPersonList(workSheetHandler.getValueList()); } /* System.out.println("\nConstructor: filePath, workSheetHandler, sheetCallback"); ExcelReader example2 = new ExcelReader(SAMPLE_PERSON_DATA_FILE_PATH, workSheetHandler, sheetCallback); example2.process(); System.out.println("\nConstructor: file, workSheetHandler, sheetCallback"); ExcelReader example3 = new ExcelReader(file, workSheetHandler, null); example3.process(); */ } catch (RuntimeException are) { LOG.error(are.getMessage(), are.getCause()); } catch (InvalidFormatException ife) { LOG.error(ife.getMessage(), ife.getCause()); } catch (IOException ioe) { LOG.error(ioe.getMessage(), ioe.getCause()); } finally { IOUtils.closeQuietly(inputStream); try { if (null != pkg) { pkg.close(); } } catch (IOException e) { // just ignore IO exception } } }
From source file:edu.harvard.i2b2.Icd9.BinResourceFromIcd9Data.java
public static void main(String[] args) { try {/*from w ww . jav a 2 s.c om*/ new BinResourceFromIcd9Data(//"/Users/kbw19/Downloads/"); "/Users/kbw19/Downloads/cmsv31-master-descriptions/"); } catch (IOException e) { // TODO Auto-generated catch block System.out.println(e.getMessage()); e.printStackTrace(); } }
From source file:framework.httpclient.nio.NHttpClient.java
public static void main(String[] args) throws Exception { // Create HTTP protocol processing chain HttpProcessor httpproc = HttpProcessorBuilder.create() // Use standard client-side protocol interceptors .add(new RequestContent()).add(new RequestTargetHost()).add(new RequestConnControl()) .add(new RequestUserAgent("LinkedHashSetVsTreeSet/1.1")).add(new RequestExpectContinue(true)) .build();/*from ww w. java 2s .c om*/ // Create client-side HTTP protocol handler HttpAsyncRequestExecutor protocolHandler = new HttpAsyncRequestExecutor(); // Create client-side I/O event dispatch // IO final IOEventDispatch ioEventDispatch = new DefaultHttpClientIODispatch(protocolHandler, ConnectionConfig.DEFAULT); // Create client-side I/O reactor // IO reactor final ConnectingIOReactor ioReactor = new DefaultConnectingIOReactor(); // Create HTTP connection pool // HTTP BasicNIOConnPool pool = new BasicNIOConnPool(ioReactor, ConnectionConfig.DEFAULT); // Limit total number of connections to just two pool.setDefaultMaxPerRoute(2); pool.setMaxTotal(2); // Run the I/O reactor in a separate thread Thread t = new Thread(new Runnable() { public void run() { try { // Ready to go! ioReactor.execute(ioEventDispatch); } catch (InterruptedIOException ex) { System.err.println("Interrupted"); } catch (IOException e) { System.err.println("I/O error: " + e.getMessage()); } System.out.println("Shutdown"); } }); // Start the client thread t.start(); // Create HTTP requester // HTTP HttpAsyncRequester requester = new HttpAsyncRequester(httpproc); // Execute HTTP GETs to the following hosts and HttpHost[] targets = new HttpHost[] { new HttpHost("www.baidu.org", -1, "https"), // new HttpHost("www.zhihu.com", -1, "https"), new HttpHost("www.bilibili.com", -1, "https") }; final CountDownLatch latch = new CountDownLatch(targets.length); for (final HttpHost target : targets) { BasicHttpRequest request = new BasicHttpRequest("GET", "/"); HttpCoreContext coreContext = HttpCoreContext.create(); requester.execute(new BasicAsyncRequestProducer(target, request), new BasicAsyncResponseConsumer(), pool, coreContext, // Handle HTTP response from a callback new FutureCallback<HttpResponse>() { public void completed(final HttpResponse response) { latch.countDown(); System.out.println(target + "->" + response.getStatusLine()); } public void failed(final Exception ex) { latch.countDown(); System.err.println(target + "->" + ex); ex.printStackTrace(); } public void cancelled() { latch.countDown(); System.out.println(target + " cancelled"); } }); } latch.await(); System.out.println("Shutting down I/O reactor"); ioReactor.shutdown(); System.out.println("Done"); }
From source file:com.hs.mail.deliver.Deliver.java
public static void main(String[] args) { CommandLine cli = null;// www . j a va2 s . c om try { cli = new PosixParser().parse(OPTS, args); } catch (ParseException e) { usage(); System.exit(EX_USAGE); } // Configuration file path String config = cli.getOptionValue("c", DEFAULT_CONFIG_LOCATION); // Message file path File file = new File(cli.getOptionValue("p")); // Envelope sender address String from = cli.getOptionValue("f"); // Destination mailboxes String[] rcpts = cli.getOptionValues("r"); if (!file.exists()) { // Message file must exist logger.error("File not exist: " + file.getAbsolutePath()); System.exit(EX_TEMPFAIL); } if (from == null || rcpts == null) { // If sender or recipients address was not specified, get the // addresses from the message header. InputStream is = null; try { is = new FileInputStream(file); MessageHeader header = new MessageHeader(is); if (from == null && header.getFrom() != null) { from = header.getFrom().getAddress(); } if (rcpts == null) { rcpts = getRecipients(header); } } catch (IOException ex) { logger.error(ex.getMessage(), ex); System.exit(EX_TEMPFAIL); } finally { IOUtils.closeQuietly(is); } } if (from == null || ArrayUtils.isEmpty(rcpts)) { usage(); System.exit(EX_USAGE); } Deliver deliver = new Deliver(); deliver.init(config); // Spool the incoming message deliver.deliver(from, rcpts, file); System.exit(EX_OK); }