List of usage examples for org.apache.commons.io IOUtils toString
public static String toString(byte[] input) throws IOException
byte[]
as a String using the default character encoding of the platform. From source file:com.swemel.sevenzip.Extract.java
public static void main(String[] args) throws IOException { String fileName = "D:\\incubator\\commpressors\\test_100K_2_b.7z"; // SevenZFile sevenZFile = new SevenZFile(new File("D:\\incubator\\commpressors\\test_100K_2_b.7z")); byte[] inputData = IOUtils.toByteArray(new FileInputStream(fileName)); // 7z archive contents SeekableInMemoryByteChannel inMemoryByteChannel = new SeekableInMemoryByteChannel(inputData); SevenZFile sevenZFile = new SevenZFile(inMemoryByteChannel); SevenZArchiveEntry entry;// w w w .java 2s . c o m Iterable<SevenZArchiveEntry> entrys = sevenZFile.getEntries(); for (SevenZArchiveEntry entry1 : entrys) { String name = entry1.getName(); System.out.println("name = " + name + "\t" + entry1.toString()); } ArrayList<InputStream> strams = sevenZFile.getStrams(); String str = IOUtils.toString(strams.get(10)); System.out.println("str = " + str); // entry = sevenZFile.getNextEntry(); // sevenZFile.read(); // read current entry's data }
From source file:com.github.fastjson.MapPractice.java
/** * @param args//ww w .j ava2 s.c o m */ public static void main(String[] args) { Map<String, String> map = new HashMap<>(); map.put("name", "doctor"); map.put("age", "1118"); map.put("sex", "man"); String jsonString = JSON.toJSONString(map); System.out.println(jsonString); InputStream resourceAsStream = MapPractice.class.getResourceAsStream("/fastjson/map1.json"); String jString = null; try { jString = IOUtils.toString(resourceAsStream); } catch (IOException e) { e.printStackTrace(); } Map<?, ?> parse = JSON.parseObject(jString, Map.class); System.out.println(parse); for (Object key : parse.keySet()) { System.out.println(key + ":" + parse.get(key)); } InputStream resourceAsStream2 = MapPractice.class.getResourceAsStream("/fastjson/map2.json"); String jString2 = null; try { jString2 = IOUtils.toString(resourceAsStream2); } catch (IOException e) { e.printStackTrace(); } Map<?, ?> parseObject = JSON.parseObject(jString2, Map.class); System.out.println(JSON.toJSON(parseObject)); System.out.println("??"); Object object = parseObject.get("currentKey"); System.out.println("currentKey" + ":" + object); Map<?, ?> object2 = (Map<?, ?>) parseObject.get("keyMap"); for (Object key : object2.keySet()) { System.out.println(key + ":" + object2.get(key)); } }
From source file:com.denimgroup.threadfix.sonarplugin.util.InputStreamLanguageDecorator.java
public static void main(String[] args) throws IOException { InputStream stream = InputStreamLanguageDecorator.class.getResourceAsStream("/threadfix_profile.xml"); stream = new InputStreamLanguageDecorator(stream, "test"); String s = IOUtils.toString(stream); System.out.println(s);//from www. j a v a 2 s .c om }
From source file:com.github.tsouza.promises.example.BlockingIOPromise.java
public static void main(String[] args) throws Exception { Promises.defer((Resolver<String> resolver) -> { URL url = new URL("http://api.ipify.org"); try (InputStream stream = url.openStream()) { resolver.resolve(IOUtils.toString(stream)); }//w ww. j av a 2 s . co m }, ThreadProfile.IO).done(System.out::println); Thread.sleep(5000); }
From source file:com.callidusrobotics.MythosRL.java
@SuppressWarnings("PMD.AvoidInstantiatingObjectsInLoops") public static void main(final String[] args) throws IOException { final Font font = FontFactory.makeTrueTypeFontResource("/fonts/Custom/Commodore64.ttf", 8.0f); ConsoleFactory.initInstance(font, 50, 80); final Console console = ConsoleFactory.getInstance(); console.setTitle(getImplementationVersion()); final XmlMarshaller xmlMarshaller = new XmlMarshaller(GameData.class); final GameData gameData = (GameData) xmlMarshaller .unMarshal(IOUtils.toString(MythosRL.class.getResourceAsStream("/data/gameData.xml"))); boolean programRunning = true; while (programRunning) { console.clear();//from w w w. j a v a 2s . c om final GameMediator mediator = new GameMediator(console, gameData); mediator.start(); while (mediator.isProgramRunning() && mediator.isGameRunning()) { console.render(); final char input = console.getKeyPress(); mediator.processInput(input); } programRunning = mediator.isProgramRunning(); if (programRunning) { console.render(); console.getKeyPress(); } } console.exit(); }
From source file:de.topobyte.jsoup.Test.java
public static void main(String[] args) throws IOException { HtmlBuilder builder = new HtmlBuilder(); Element head = builder.getHead(); String header = IOUtils.toString( Thread.currentThread().getContextClassLoader().getResourceAsStream("bootstrap.headers.html")); System.out.println(header);//from w ww. ja v a 2 s . co m ElementUtil.appendFragment(head, header); Element body = builder.getBody(); // Menu Menu menu = new Menu(); body.ap(menu); menu.addBrand(HTML.span().appendText("Awesome")); menu.addMain(a("#").appendText("Products"), false); menu.addMain(a("#").appendText("Services"), false); menu.addMain(a("#").appendText("Partners"), false); menu.addRight(a("#").appendText("About"), false); // Content Container c = body.ac(Bootstrap.container()); Breadcrumb breadcrumb = Bootstrap.breadcrumb(); c.ap(breadcrumb); breadcrumb.addTextItem("foo"); breadcrumb.addTextItem("bar"); breadcrumb.addTextItem("and"); breadcrumb.addTextItem("so on"); c.ap(h1().inner("The headline")); Div div = c.ac(div("foo")); Element p = div.ac(p().inner("this is a paragraph in a div. ")); System.out.println(p); p.ap(b().inner("bold")); p.appendText(" and "); p.ap(i().inner("italic")); p.appendText(" text is possible as well"); System.out.println(p); div.ap(button().inner("I'm a button")); Document doc = builder.getDocument(); System.out.println(doc); builder.write(new File("/tmp/jsoup-bootstrap.html")); }
From source file:com.atlauncher.Bootstrap.java
public static void main(String[] args) { String json = null;/*w w w.ja v a 2 s . c om*/ if (!Files.isDirectory(PATH)) { try { Files.createDirectories(PATH); } catch (IOException e) { e.printStackTrace(); } } try { json = IOUtils.toString(URI.create("http://download.nodecdn.net/containers/atl/v4/app.json")); } catch (IOException e) { e.printStackTrace(); System.exit(1); } Application application = GSON.fromJson(json, Application.class); Dependency currentDependency = null; if (Files.exists(PATH.resolve("nwjs.json"))) { try { currentDependency = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("nwjs.json").toFile()), Dependency.class); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } for (Dependency dependency : application.getDependencies()) { if (dependency.shouldInstall() && !dependency.matches(currentDependency)) { if (Files.isDirectory(PATH.resolve("nwjs/"))) { try { FileUtils.deleteDirectory(PATH.resolve("nwjs/").toFile()); } catch (IOException e) { e.printStackTrace(); } } try { File zipFile = PATH.resolve("nwjs/temp.zip").toFile(); FileUtils.copyURLToFile(dependency.getUrl(), zipFile); Utils.unzip(zipFile, PATH.resolve("nwjs/").toFile()); FileUtils.forceDelete(zipFile); currentDependency = dependency; FileUtils.writeStringToFile(PATH.resolve("nwjs.json").toFile(), GSON.toJson(dependency)); break; } catch (IOException e) { e.printStackTrace(); System.exit(1); } } } App currentApp = null; if (Files.exists(PATH.resolve("app.json"))) { try { currentApp = GSON.fromJson(FileUtils.readFileToString(PATH.resolve("app.json").toFile()), App.class); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } if (!application.getApp().matches(currentApp) || (currentApp != null && !Files.exists(PATH.resolve(currentApp.getFilename())))) { if (currentApp != null && Files.exists(PATH.resolve(currentApp.getFilename()))) { try { FileUtils.forceDelete(PATH.resolve(currentApp.getFilename()).toFile()); } catch (IOException e) { e.printStackTrace(); } } try { FileUtils.copyURLToFile(application.getApp().getUrl(), PATH.resolve(application.getApp().getFilename()).toFile()); currentApp = application.getApp(); FileUtils.writeStringToFile(PATH.resolve("app.json").toFile(), GSON.toJson(application.getApp())); } catch (IOException e) { e.printStackTrace(); System.exit(1); } } if (currentDependency == null || currentApp == null) { System.exit(1); } List<String> arguments = new ArrayList<>(); arguments.add(PATH.resolve("nwjs/").toAbsolutePath() + currentDependency.getStartup()); arguments.add(currentApp.getFilename()); ProcessBuilder processBuilder = new ProcessBuilder(arguments); processBuilder.directory(PATH.toFile()); try { processBuilder.start(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.sanjeev.sample.JsonParserExample.java
/** * @param args/*from w w w.j a v a 2 s . co m*/ * @throws IOException * @throws JSONException */ public static void main(String[] args) throws JSONException, IOException { InputStream is = JsonParserExample.class.getResourceAsStream("/events-groups.json"); JSONObject groups = new JSONObject(IOUtils.toString(is)); // formatMessage(groups, "ConsoleLogin"); }
From source file:com.apipulse.bastion.Main.java
public static void main(String[] args) throws IOException, ClassNotFoundException { log.info("Bastion starting. Loading chains"); final File dir = new File("etc/chains"); final LinkedList<ActorRef> chains = new LinkedList<ActorRef>(); for (File file : dir.listFiles()) { if (!file.getName().startsWith(".") && file.getName().endsWith(".yaml")) { log.info("Loading chain: " + file.getName()); ChainConfig config = new ChainConfig(IOUtils.toString(new FileReader(file))); ActorRef ref = BastionActors.getInstance().initChain(config.getName(), Class.forName(config.getQualifiedClass())); Iterator<StageConfig> iterator = config.getStages().iterator(); while (iterator.hasNext()) ref.tell(iterator.next(), null); chains.add(ref);//from w ww . jav a 2s. c o m } } SpringApplication app = new SpringApplication(); HashSet<Object> objects = new HashSet<Object>(); objects.add(ApiController.class); final ConfigurableApplicationContext context = app.run(ApiController.class, args); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { log.info("Bastion shutting down"); Iterator<ActorRef> iterator = chains.iterator(); while (iterator.hasNext()) iterator.next().tell(new StopMessage(), null); Thread.sleep(2000); context.stop(); log.info("Bastion shutdown complete"); } catch (Exception e) { } } }); }
From source file:io.zz.TestSaveToCassandra.java
public static void main(String[] args) throws IOException, InterruptedException { SparkConf conf = new SparkConf().setAppName("aaaa").setMaster("spark://192.168.100.105:7077") .set("spark.serializer", "org.apache.spark.serializer.KryoSerializer") .set("spark.cassandra.connection.host", "192.168.100.105"); JavaStreamingContext streamingContext = new JavaStreamingContext(conf, new Duration(10000)); JavaDStream<String> stream = streamingContext.socketTextStream("192.168.100.105", 9999); // stream.count().print(); SQLContext sql = SQLContext.getOrCreate(streamingContext.sparkContext().sc()); Dataset<Name> ds = sql.createDataset(ImmutableList.of(new Name("a", "b")), Encoders.bean(Name.class)); CassandraConnector cc = CassandraConnector.apply(conf); try (Session session = cc.openSession()) { String file = IOUtils.toString(TestSaveToCassandra.class.getResourceAsStream("/c.sql")); Arrays.stream(file.split(";")).map(s -> s.trim()).filter(s -> !s.isEmpty()).map(s -> s + ";") .forEach((String str) -> session.execute(str)); }/*ww w . j a va2s . co m*/ // ds.toDF().write().mode(SaveMode.Overwrite).option("truncate", "true").jdbc("", "", new Properties()); JavaDStream<Name> map = stream.map(s -> new Name(s, "e")); map.foreachRDD((s, t) -> process(s)); CassandraStreamingJavaUtil.javaFunctions(map) .writerBuilder("keyspace1", "name", CassandraJavaUtil.mapToRow(Name.class)).saveToCassandra(); streamingContext.start(); streamingContext.awaitTermination(); streamingContext.stop(); }