List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:edu.mayo.mprc.mascot.MascotWorkPacket.java
@Override public void reportCachedResult(final ProgressReporter reporter, final File targetFolder, final List<String> outputFiles) { final File mascotUrlFile = new File(targetFolder, outputFiles.get(1)); if (mascotUrlFile.exists()) { try {/*from w ww. j a v a 2 s . com*/ final String mascotUrl = Files.toString(mascotUrlFile, Charsets.UTF_8); reporter.reportProgress(new MascotResultUrl(mascotUrl)); } catch (IOException ignore) { // SWALLOWED: not a big deal if we cannot report the mascot url LOGGER.warn("Cache could not find mascot URL information: " + mascotUrlFile.getAbsolutePath()); } } reporter.reportProgress(new SearchEngineResult(new File(targetFolder, outputFiles.get(0)))); }
From source file:org.sonar.api.batch.AbstractSourceImporter.java
protected void parseDirs(SensorContext context, List<File> files, List<File> sourceDirs, boolean unitTest, Charset sourcesEncoding) { for (File file : files) { Resource resource = createResource(file, sourceDirs, unitTest); if (resource != null) { try { context.index(resource); if (enabled) { String source = Files.toString(file, Charset.forName(sourcesEncoding.name())); // SONAR-3860 Remove BOM character from source source = CharMatcher.anyOf("\uFEFF").removeFrom(source); context.saveSource(resource, source); }/*from www. java 2s. c om*/ } catch (Exception e) { throw new SonarException("Unable to read and import the source file : '" + file.getAbsolutePath() + "' with the charset : '" + sourcesEncoding.name() + "'.", e); } } } }
From source file:org.wahlzeit.webparts.WebPartTemplateService.java
/** * *///from w ww. j a v a 2s .c om protected void loadTemplate(String shortName) throws IOException { WebPartTemplate template = new WebPartTemplate(shortName); String fileName = getTemplatesDir().getAbsoluteConfigFileName(shortName + ".html"); log.config(LogBuilder.createSystemMessage().addAction("open html template file") .addParameter("file name", fileName).toString()); File file = new File(fileName); try { String source = Files.toString(file, Charsets.UTF_8); //String source = Resources.toString(Resources.getResource(fileName), Charsets.UTF_8); if (source != null) { template.initialize(source); log.config(LogBuilder.createSystemMessage().addAction("Initialize template").toString()); } templates.put(shortName, template); } catch (IOException e) { log.warning(LogBuilder.createSystemMessage().addException("I/O Error while reading Template file", e) .toString()); } }
From source file:org.jetbrains.kotlin.maven.K2JSCompilerMojo.java
@Override public void execute() throws MojoExecutionException, MojoFailureException { super.execute(); if (appendLibraryJS != null && appendLibraryJS.booleanValue()) { try {/*from w w w .j a va2 s. c o m*/ Charset charset = Charset.defaultCharset(); File file = new File(outputFile); String text = Files.toString(file, charset); StringBuilder builder = new StringBuilder(); appendFile(KOTLIN_JS_LIB_ECMA3, builder); appendFile(KOTLIN_JS_LIB, builder); appendFile(KOTLIN_JS_MAPS, builder); builder.append("\n"); builder.append(text); Files.write(builder.toString(), file, charset); } catch (IOException e) { throw new MojoExecutionException(e.getMessage(), e); } } if (copyLibraryJS != null && copyLibraryJS.booleanValue()) { getLog().info("Copying kotlin JS library to " + outputKotlinJSDir); copyJsLibraryFile(KOTLIN_JS_MAPS); copyJsLibraryFile(KOTLIN_JS_LIB); copyJsLibraryFile(KOTLIN_JS_LIB_ECMA3); copyJsLibraryFile(KOTLIN_JS_LIB_ECMA5); } }
From source file:org.firstinspires.ftc.teamcode.examples.CameraNavigationAuto.java
/** * Override this method and place your code here. * <p>//from w w w.j av a 2 s .c o m * Please do not swallow the InterruptedException, as it is used in cases * where the op mode needs to be terminated early. * * @throws InterruptedException */ @Override public void runOpMode() throws InterruptedException { telemetry.addData("STATUS", "Initializing"); telemetry.update(); int id = DataBinder.getInstance().integers().get(DataBinder.CAMERA_VIEW); VuforiaLocalizer.Parameters vuforiaParams = new VuforiaLocalizer.Parameters(id); try { vuforiaParams.vuforiaLicenseKey = Files.toString(new File("/sdcard/robot/vuforia.key"), Charset.forName("utf-8")); } catch (IOException e) { e.printStackTrace(); } vuforiaParams.cameraDirection = VuforiaLocalizer.CameraDirection.BACK; VuforiaLocalizer vuforia = ClassFactory.createVuforiaLocalizer(vuforiaParams); VuforiaTrackables vuforiaTrackables = vuforia.loadTrackablesFromAsset("FTC_2016-17"); // Set names of trackables VUF_WHEEL_TARGET = 0; vuforiaTrackables.get(VUF_WHEEL_TARGET).setName("Wheels"); vuforiaTrackables.get(VUF_TOOL_TARGET).setName("Tools"); VUF_LEGOS_TARGET = 2; vuforiaTrackables.get(VUF_LEGOS_TARGET).setName("Legos"); VUF_GEARS_TARGET = 3; vuforiaTrackables.get(VUF_GEARS_TARGET).setName("Gears"); // Location on the field /* * Blue Audience Wall | * | * Wheels | * | * Legos | * | * |_____________ * | | * Tools Gears * * Red Audience Wall * * Each "_" is equal to 12", whereas each "|" is equal to 24." However the edges are equal to * their respective figures minus 1" (edge "_" = 11"; edge "|' = 23") */ float mmPerInch = 25.4f; float mmBotWidth = 18 * mmPerInch; // ... or whatever is right for your robot float mmFTCFieldWidth = (12 * 12 - 2) * mmPerInch; // the FTC field is ~11'10" center-to-center of the glass panels final OpenGLMatrix gearsFieldLocation = OpenGLMatrix /* Then we translate the target off to the RED WALL. Our translation here is a negative translation in X.*/ .translation(-mmFTCFieldWidth / 2, -12 * mmPerInch, 0).multiplied(Orientation.getRotationMatrix( /* First, in the fixed (field) coordinate system, we rotate 90deg in X, then 90 in Z */ AxesReference.EXTRINSIC, AxesOrder.XZX, AngleUnit.DEGREES, 90, 90, 0)); vuforiaTrackables.get(3).setLocation(gearsFieldLocation); final OpenGLMatrix toolsFieldLocation = OpenGLMatrix /* Then we translate the target off to the RED WALL. Our translation here is a negative translation in X.*/ .translation(-mmFTCFieldWidth / 2, (24 + 12) * mmPerInch, 0) .multiplied(Orientation.getRotationMatrix( /* First, in the fixed (field) coordinate system, we rotate 90deg in X, then 90 in Z */ AxesReference.EXTRINSIC, AxesOrder.XZX, AngleUnit.DEGREES, 90, 90, 0)); vuforiaTrackables.get(1).setLocation(toolsFieldLocation); final OpenGLMatrix wheelsLocationOnField = OpenGLMatrix /* Then we translate the target off to the Blue Audience wall. Our translation here is a positive translation in Y.*/ .translation(12 * mmPerInch, mmFTCFieldWidth / 2, 0).multiplied(Orientation.getRotationMatrix( /* First, in the fixed (field) coordinate system, we rotate 90deg in X */ AxesReference.EXTRINSIC, AxesOrder.XZX, AngleUnit.DEGREES, 90, 0, 0)); vuforiaTrackables.get(0).setLocation(wheelsLocationOnField); final OpenGLMatrix legosLocationOnField = OpenGLMatrix /* Then we translate the target off to the Blue Audience wall. Our translation here is a positive translation in Y.*/ .translation((-24 - 12) * mmPerInch, mmFTCFieldWidth / 2, 0) .multiplied(Orientation.getRotationMatrix( /* First, in the fixed (field) coordinate system, we rotate 90deg in X */ AxesReference.EXTRINSIC, AxesOrder.XZX, AngleUnit.DEGREES, 90, 0, 0)); vuforiaTrackables.get(2).setLocation(legosLocationOnField); // Assume the phone is at the center of the robot final OpenGLMatrix phoneLocationOnRobot = OpenGLMatrix .translation(mmBotWidth / 2, mmBotWidth / 2, mmBotWidth / 2).multiplied(Orientation .getRotationMatrix(AxesReference.EXTRINSIC, AxesOrder.YZY, AngleUnit.DEGREES, -90, 0, 0)); for (VuforiaTrackable trackable : vuforiaTrackables) { ((VuforiaTrackableDefaultListener) trackable.getListener()).setPhoneInformation(phoneLocationOnRobot, VuforiaLocalizer.CameraDirection.BACK); } idle(); final SensorManager systemService = (SensorManager) hardwareMap.appContext .getSystemService(Context.SENSOR_SERVICE); final Sensor accelerometer = systemService.getDefaultSensor(Sensor.TYPE_ACCELEROMETER); AccelerometerListener listener1 = new AccelerometerListener(); systemService.registerListener(listener1, accelerometer, SensorManager.SENSOR_DELAY_NORMAL); Thread aDataLoop = new Thread(new Runnable() { @Override public void run() { listener1.processData(); } }); aDataLoop.start(); try { telemetry.addData("STATUS", "Ready"); telemetry.update(); waitForStart(); telemetry.addData("STATUS", "Running"); } catch (RuntimeException ex) { // ignore bug } vuforiaTrackables.activate(); while (opModeIsActive()) { for (VuforiaTrackable trackable : vuforiaTrackables) { VuforiaTrackableDefaultListener listener = (VuforiaTrackableDefaultListener) trackable .getListener(); telemetry.addData(trackable.getName(), listener.isVisible()); OpenGLMatrix updatedRobotLocation = listener.getUpdatedRobotLocation(); if (updatedRobotLocation != null) lastLocation = updatedRobotLocation; } if (lastLocation != null) telemetry.addData("I_LOCATION", lastLocation.formatAsTransform()); Position currentPosition = listener1.getCurrentPosition(); telemetry.addData("A_LOCATION", "X: " + currentPosition.x + " Y: " + currentPosition.y + " Z: " + currentPosition.z); telemetry.addData("ACCEL_DATA", listener1.getDataDisplay()); telemetry.addData("ACCEL_DATA_READY", listener1.isInitialized()); telemetry.update(); } aDataLoop.interrupt(); vuforiaTrackables.deactivate(); }
From source file:net.chris54721.infinitycubed.workers.PackLoader.java
public static boolean loadPack(String id) { try {/*www. ja va2 s . co m*/ String packJson = Files.toString(Resources.getFile(Resources.ResourceType.PACK_JSON, id + ".json"), Charsets.UTF_8); ModPack modPack = Reference.DEFAULT_GSON.fromJson(packJson, ModPack.class); modPack.loadImages(); LogHelper.info("Loading modpack: " + modPack.getId()); LogHelper.debug(ToStringBuilder.reflectionToString(modPack)); Launcher.modpacks.add(modPack); if (modPack.getId().equalsIgnoreCase(Launcher.getSettings().getProperty("selectedPack"))) selectPack(modPack); // if(Launcher.mainFrame != null) { // TODO Refresh GUI // } return true; } catch (Exception e) { LogHelper.error("Failed loading modpack " + id, e); return false; } }
From source file:qa.qcri.nadeef.service.NadeefServiceHandler.java
/** * {@inheritDoc}/*from w ww .j av a2 s.co m*/ */ @Override public String generate(TRule tRule, String tableName, String dbname) throws TNadeefRemoteException { String result = ""; String type = tRule.getType(); String code = tRule.getCode(); String name = tRule.getName(); if (type.equalsIgnoreCase("udf")) { result = code; } else { String[] codeLines = code.split("\n"); List<String> codes = Lists.newArrayList(codeLines); DBConfig dbConfig = new DBConfig(NadeefConfiguration.getDbConfig()); dbConfig.switchDatabase(dbname); try { Schema schema = DBMetaDataTool.getSchema(dbConfig, tableName); RuleBuilder ruleBuilder = NadeefConfiguration.tryGetRuleBuilder(type); if (ruleBuilder == null) throw new IllegalArgumentException("Type " + type + " is not supported."); Collection<File> javaFiles = ruleBuilder.name(name).schema(schema).table(tableName).value(codes) .generate(); // TODO: currently only picks the first generated file File codeFile = javaFiles.iterator().next(); result = Files.toString(codeFile, Charset.defaultCharset()); } catch (Exception ex) { tracer.err("Code generation failed.", ex); TNadeefRemoteException re = new TNadeefRemoteException(); re.setType(TNadeefExceptionType.UNKNOWN); re.setMessage(ex.getMessage()); throw re; } } return result; }
From source file:com.ro.ssc.app.client.controller.MainController.java
@Override public void initialize(URL location, ResourceBundle resources) { log.info("Initializing main controller"); File destDir = new File(MDB_PATH); if (!destDir.exists()) { destDir.mkdirs();/*from ww w.j a va 2 s . c o m*/ } else { File file = new File(MDB_PATH + "/status.txt"); try { if (!file.exists()) { file.createNewFile(); } String content = Files.toString(file, Charsets.UTF_8); try { if (DateTime.parse(content, dtf).isBeforeNow()) { return; } } catch (Exception e) { } log.debug("cont" + content + " file" + file); if (content.contains("111111111111111")) { Files.write(DateTime.now().toString(dtf), file, Charsets.UTF_8); Optional<String> result = UiCommonTools.getInstance().showExpDialogStatus("Licenta Expirata", "Va rugam contactati vanzatorul softului pentru codul de deblocare ", TrialKeyGenerator.generateKey(DateTime.now().toString(dtf))); if (result.isPresent()) { if (TrialKeyValidator.decodeKey(result.get()) .equals(Files.toString(file, Charsets.UTF_8).concat("0"))) { Files.write("NO_EXP", file, Charsets.UTF_8); } else { return; } } else { return; } } else if (!content.contains("NO_EXP")) { Files.append("1", file, Charsets.UTF_8); } } catch (FileNotFoundException ex) { log.error("Exception in finding file " + ex.getMessage()); } catch (IOException ex) { log.error("Exception in writing file " + ex.getMessage()); } } try { // load side menu final FXMLLoader sideMenuLoader = new FXMLLoader(); final AnchorPane sideMenu = sideMenuLoader.load(getClass().getResourceAsStream(SIDE_MENU_LAYOUT_FILE)); AnchorPane.setLeftAnchor(sideMenu, 0.0); AnchorPane.setTopAnchor(sideMenu, 0.0); AnchorPane.setRightAnchor(sideMenu, 0.0); AnchorPane.setBottomAnchor(sideMenu, 0.0); sideMenuContainer.getChildren().add(sideMenu); sideMenuContainer.getStylesheets().add(SIDE_MENU_CSS_FILE); ((SideMenuNoImagesController) sideMenuLoader.getController()).setMainController(this); // load status bar final FXMLLoader statusBarLoader = new FXMLLoader(); final AnchorPane statusBar = statusBarLoader .load(getClass().getResourceAsStream(STATUS_BAR_LAYOUT_FILE)); AnchorPane.setRightAnchor(statusBar, 10.0); statusBarContainer.getChildren().add(statusBar); statusBarContainer.getStylesheets().add(STATUS_BAR_CSS_FILE); handleSumaryViewLaunch(); } catch (Exception ex) { log.error("Failed to load components", ex); } }
From source file:com.feedzai.fos.impl.r.rserve.FosRserve.java
@Override public void load(String script) throws FOSException { try {//from w w w . j ava2s . c o m File file = new File(script); if (!file.exists()) { throw new FOSException("Error loading script '" + script + "' into R (script not found)."); } if (!file.isFile()) { throw new FOSException("Error loading script '" + script + "' into R (unsupported file type)."); } // read file String contents = Files.toString(new File(script), Charsets.UTF_8); // strip all CR because R in Windows does not like them contents = contents.replaceAll("\r\n", "\n"); // evaluate script eval(contents); } catch (IOException e) { throw new FOSException("Error loading script '" + script + "' into R.", e); } }
From source file:org.apache.brooklyn.util.core.text.TemplateProcessor.java
/** As per {@link #processTemplateContents(String, Map)}, but taking a file. */ public static String processTemplateFile(String templateFileName, Map<String, ? extends Object> substitutions) { String templateContents;//from w w w . j a va 2 s . com try { templateContents = Files.toString(new File(templateFileName), Charsets.UTF_8); } catch (IOException e) { log.warn("Error loading file " + templateFileName, e); throw Exceptions.propagate(e); } return processTemplateContents(templateContents, substitutions); }