List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:com.github.rinde.rinsim.examples.fabrirecht.simple.FabriRechtExample.java
/** * Starts the example./*from w ww .j ava 2 s . co m*/ * @param args Ignored. * @throws IOException If file can not be loaded. */ public static void main2(String[] args) throws IOException { // we load a problem instance from disk, we instantiate it with 8 // trucks, each with a capacity of 20 units final FabriRechtScenario scenario = FabriRechtParser.fromJson( Files.toString(new File("../scenario-util/files/test/fabri-recht/lc101.scenario"), Charsets.UTF_8), 8, 20); // instantiate the simulator using the scenario final Simulator sim = Simulator.builder() .addModel(ScenarioController.builder(scenario) .withEventHandler(AddParcelEvent.class, AddParcelEvent.defaultHandler()) .withEventHandler(AddVehicleEvent.class, new TimedEventHandler<AddVehicleEvent>() { @Override public void handleTimedEvent(AddVehicleEvent event, SimulatorAPI s) { s.register(new Truck(event.getVehicleDTO())); } })) .addModel(StatsTracker.builder()) .addModel(View.builder().withAutoPlay().with(PlaneRoadModelRenderer.builder()) .with(PDPModelRenderer.builder()).with(RoadUserRenderer.builder())) .build(); // start the simulation sim.start(); // simulation is done, lets print the statistics! System.out.println(sim.getModelProvider().getModel(StatsTracker.class).getStatistics()); }
From source file:com.google.gwt.site.uploader.CredentialsProvider.java
public RemoteApiOptions readCredentialsFromFile(String credentialsFile) throws IOException { String serialized = Files.toString(new File(credentialsFile), Charsets.UTF_8); Map<String, List<String>> props = parseProperties(serialized); checkOneProperty(props, "host"); checkOneProperty(props, "email"); String host = props.get("host").get(0); String email = props.get("email").get(0); int port = 443; try {/*from w w w .ja v a 2 s . c o m*/ if (props.containsKey("port")) { checkOneProperty(props, "port"); port = Integer.parseInt(props.get("port").get(0)); } } catch (NumberFormatException e) { logger.log(Level.SEVERE, "error while parsing port", e); throw new RuntimeException("error while parsing port"); } return new RemoteApiOptions().server(host, port).reuseCredentials(email, serialized); }
From source file:org.apache.jclouds.ProviderConfig.java
/** * Reads a given file and returns a String with the contents. *//*from w w w. j av a 2 s . co m*/ private static String fileContents(final String path) throws IOException { return Files.toString(new File(path), Charsets.UTF_8); }
From source file:br.com.objectos.jabuticava.debs.Caracteristica.java
public static Caracteristica parse(File file) { try {//w w w. j ava 2 s. c om String text = Files.toString(file, CHARSET); return parseString(text); } catch (IOException e) { return Caracteristica.vazio(); } }
From source file:org.eclipse.scout.docs.publish.PublishUtility.java
/** * Take a single HTML file and publish it to the outFolder. * Images and CSS resources are moved.//from w w w .j a va 2 s . com * * @param inFolder * root folder where the input HTML file is located. * @param inFileName * name of the input HTML file (with extension) * @param outFolder * directory where the post-processed HTML file is saved. * @throws IOException */ public static void publishHtmlFile(File inFolder, String inFileName, File outFolder) throws IOException { if (!inFolder.exists() || !inFolder.isDirectory()) { throw new IllegalStateException("Folder inFolder '" + inFolder.getAbsolutePath() + "' not found."); } File inFile = new File(inFolder, inFileName); if (!inFile.exists()) { throw new IllegalStateException("File inFile '" + inFolder.getAbsolutePath() + "' does not exist."); } File outFile = new File(outFolder, inFile.getName()); String html = Files.toString(inFile, Charsets.ISO_8859_1); Document doc = Jsoup.parse(html); doc.outputSettings().charset("ASCII"); fixListingLink(doc); fixFigureLink(doc); Files.createParentDirs(outFile); moveAndcopyImages(doc, inFolder, outFolder, "images/"); Files.write(doc.toString(), outFile, Charsets.ISO_8859_1); }
From source file:org.apache.drill.exec.pop.PopUnitTestBase.java
public static Fragment getRootFragment(PhysicalPlanReader reader, String file) throws FragmentSetupException, IOException, ForemanSetupException { return getRootFragmentFromPlanString(reader, Files.toString(FileUtils.getResourceAsFile(file), Charsets.UTF_8)); }
From source file:org.sonarlint.cli.config.ConfigurationReader.java
private static String getContents(Path filePath) { try {/* w ww . j a v a 2 s . c o m*/ return Files.toString(filePath.toFile(), Charsets.UTF_8); } catch (IOException e) { throw new IllegalStateException("Error reading configuration file: " + filePath.toAbsolutePath(), e); } }
From source file:gem.talk_to_outside_world.validation.JsonLogger.java
private static String readJsonFromFile(File file) { String json = ""; try {//ww w . j av a 2 s . c om json = Files.toString(file, Charsets.UTF_8); } catch (Exception ex) { ex.printStackTrace(); } return json; }
From source file:org.apache.flume.channel.file.encryption.EncryptionTestUtils.java
public static void createKeyStore(File keyStoreFile, File keyStorePasswordFile, Map<String, File> keyAliasPassword) throws Exception { KeyStore ks = KeyStore.getInstance("jceks"); ks.load(null);/*w ww .j av a 2 s . c o m*/ List<String> keysWithSeperatePasswords = Lists.newArrayList(); for (String alias : keyAliasPassword.keySet()) { Key key = newKey(); char[] password = null; File passwordFile = keyAliasPassword.get(alias); if (passwordFile == null) { password = Files.toString(keyStorePasswordFile, Charsets.UTF_8).toCharArray(); } else { keysWithSeperatePasswords.add(alias); password = Files.toString(passwordFile, Charsets.UTF_8).toCharArray(); } ks.setKeyEntry(alias, key, password, null); } char[] keyStorePassword = Files.toString(keyStorePasswordFile, Charsets.UTF_8).toCharArray(); FileOutputStream outputStream = new FileOutputStream(keyStoreFile); ks.store(outputStream, keyStorePassword); outputStream.close(); }
From source file:de.hh.changeRing.migration.ParseDumpFile.java
private ParseDumpFile(File from, File toFolder) { try {/*from w ww . ja v a2s . c o m*/ this.content = Files.toString(from, UTF_8); replace("`", ""); replace("SET @saved_cs_client = @@character_set_client;", ""); replace("SET character_set_client = utf8;", ""); replace("SET character_set_client = @saved_cs_client;", ""); //content = content.replaceAll("ENGINE=MyISAM AUTO_INCREMENT=[0-9]+ DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci", ""); replace("ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_german2_ci PACK_KEYS=0;", ""); //replace("text collate latin1_german2_ci", "varchar(2048)"); //replace("collate latin1_german2_ci ", ""); //replace(" auto_increment", ""); replace("\\'", "''"); replace("),(", ")\n,("); content = content.replaceAll("LOCK TABLES [a-z]+ WRITE;", ""); replace("UNLOCK TABLES;", ""); toFolder.delete(); toFolder.mkdirs(); for (String contentPart : Splitter.on("DROP TABLE IF EXISTS ").split(content)) { String tableName = contentPart.substring(0, contentPart.indexOf(';')); if (!tableName.contains(" ")) { File file = new File(toFolder, tableName + ".sql"); file.delete(); Files.write("DROP TABLE IF EXISTS " + contentPart, file, UTF_8); log(tableName, file, contentPart); } } } catch (IOException e) { throw new RuntimeException(e); } }