List of usage examples for com.google.common.io Files toString
public static String toString(File file, Charset charset) throws IOException
From source file:org.jclouds.docker.suppliers.SSLContextBuilder.java
private static String loadFile(final String filePath) throws IOException { return Files.toString(new File(filePath), Charsets.UTF_8); }
From source file:com.zack6849.alphabot.api.PermissionManager.java
/** * Returns the group a user belongs to, this ignores default * If a user belongs to two groups, then it will return the first it finds. * * @param user the User object to get the group of * @return the Group the user belongs to *///from www . ja va2 s . c o m public Group getUserGroup(User user) { //first check if any of the groups contain the user for (Group g : getGroups()) { if (!g.getName().equalsIgnoreCase("default")) { for (User u : g.getUsers().keySet()) { if (u == user) { return g; } } } } //if they haven't, parse all the json String json = null; try { json = Files.toString(new File("permissions.json"), Charset.isSupported("UTF-8") ? Charset.forName("UTF-8") : Charset.defaultCharset()); JsonElement jelement = new JsonParser().parse(json); JsonObject output = jelement.getAsJsonObject(); Set<Map.Entry<String, JsonElement>> users = output.get("users").getAsJsonObject().entrySet(); boolean hostmatch = false; Iterator it = users.iterator(); int count = 0; while (it.hasNext()) { count++; Object next = it.next(); Map.Entry en = (Map.Entry) next; String mask = en.getKey().toString().replaceAll("\"", ""); String rank = en.getValue().toString().replaceAll("\"", ""); Pattern p = Pattern.compile(mask.split("\\@")[0].replaceAll("\\*", ".*")); Matcher m = p.matcher(user.getNick()); if (m.find()) { p = Pattern.compile(mask.split("\\@")[1].replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*")); m = p.matcher(user.getHostmask()); if (m.find()) { Group target = getGroupByName(rank); target.addUser(user, mask); return target; } } } } catch (IOException e) { e.printStackTrace(); } return getGroupByName("Default"); }
From source file:com.android.tools.idea.fd.gradle.InstantRunGradleUtils.java
@Nullable public static InstantRunBuildInfo getBuildInfo(@NonNull AndroidModuleModel model) { File buildInfo = getLocalBuildInfoFile(model); if (!buildInfo.exists()) { return null; }//from www.j av a 2s .c o m String xml; try { xml = Files.toString(buildInfo, Charsets.UTF_8); } catch (IOException e) { return null; } return InstantRunBuildInfo.get(xml); }
From source file:net.sf.lucis.core.impl.ReindexingFSStore.java
public String getCheckpoint() throws StoreException { if (!checkpointFile.exists()) { return null; }/* www . j a v a2s .c om*/ try { return Files.toString(checkpointFile, Charsets.UTF_8); } catch (IOException e) { return null; } }
From source file:org.jclouds.tools.ant.taskdefs.compute.ComputeTaskUtils.java
static void addPrivateKeyToOptionsIfPresentInNodeElement(NodeElement nodeElement, TemplateOptions options) throws IOException { if (nodeElement.getPrivatekeyfile() != null) options.installPrivateKey(Files.toString(nodeElement.getPrivatekeyfile(), Charsets.UTF_8)); }
From source file:org.saintandreas.util.XmlUtil.java
public static Document parseXmlFile(File path, Charset charset) throws SAXException, IOException, ParserConfigurationException { return parseXmlString(Files.toString(path, charset)); }
From source file:net.poemerchant.scraper.ShopScraper.java
private String loadJSParser(String jsFile) { String js = null;/* w w w .j a va2 s .co m*/ try { js = Files.toString(new File(jsFile), Charsets.UTF_8); } catch (IOException e) { throw new PoEMerchantRuntimeException(e); } return js; }
From source file:org.sonar.javascript.parser.sslr.ActionParser2.java
@Override public AstNode parse(File file) { try {/*from w w w . j a va 2 s . c o m*/ return parse(new Input(Files.toString(file, charset).toCharArray(), file.toURI())); } catch (IOException e) { throw Throwables.propagate(e); } }
From source file:org.apache.flume.source.jms.JMSSource.java
@Override protected void doConfigure(Context context) throws FlumeException { sourceCounter = new SourceCounter(getName()); initialContextFactoryName = context.getString(JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY, "").trim(); providerUrl = context.getString(JMSSourceConfiguration.PROVIDER_URL, "").trim(); destinationName = context.getString(JMSSourceConfiguration.DESTINATION_NAME, "").trim(); String destinationTypeName = context.getString(JMSSourceConfiguration.DESTINATION_TYPE, "").trim() .toUpperCase(Locale.ENGLISH); String destinationLocatorName = context.getString(JMSSourceConfiguration.DESTINATION_LOCATOR, JMSSourceConfiguration.DESTINATION_LOCATOR_DEFAULT).trim().toUpperCase(Locale.ENGLISH); messageSelector = context.getString(JMSSourceConfiguration.MESSAGE_SELECTOR, "").trim(); batchSize = context.getInteger(JMSSourceConfiguration.BATCH_SIZE, JMSSourceConfiguration.BATCH_SIZE_DEFAULT); errorThreshold = context.getInteger(JMSSourceConfiguration.ERROR_THRESHOLD, JMSSourceConfiguration.ERROR_THRESHOLD_DEFAULT); userName = Optional.fromNullable(context.getString(JMSSourceConfiguration.USERNAME)); pollTimeout = context.getLong(JMSSourceConfiguration.POLL_TIMEOUT, JMSSourceConfiguration.POLL_TIMEOUT_DEFAULT); String passwordFile = context.getString(JMSSourceConfiguration.PASSWORD_FILE, "").trim(); if (passwordFile.isEmpty()) { password = Optional.of(""); } else {//from ww w. j ava 2 s. com try { password = Optional.of(Files.toString(new File(passwordFile), Charsets.UTF_8).trim()); } catch (IOException e) { throw new FlumeException(String.format("Could not read password file %s", passwordFile), e); } } String converterClassName = context .getString(JMSSourceConfiguration.CONVERTER_TYPE, JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT) .trim(); if (JMSSourceConfiguration.CONVERTER_TYPE_DEFAULT.equalsIgnoreCase(converterClassName)) { converterClassName = DefaultJMSMessageConverter.Builder.class.getName(); } Context converterContext = new Context(context.getSubProperties(JMSSourceConfiguration.CONVERTER + ".")); try { @SuppressWarnings("rawtypes") Class clazz = Class.forName(converterClassName); boolean isBuilder = JMSMessageConverter.Builder.class.isAssignableFrom(clazz); if (isBuilder) { JMSMessageConverter.Builder builder = (JMSMessageConverter.Builder) clazz.newInstance(); converter = builder.build(converterContext); } else { Preconditions.checkState(JMSMessageConverter.class.isAssignableFrom(clazz), String.format("Class %s is not a subclass of JMSMessageConverter", clazz.getName())); converter = (JMSMessageConverter) clazz.newInstance(); boolean configured = Configurables.configure(converter, converterContext); if (logger.isDebugEnabled()) { logger.debug(String.format("Attempted configuration of %s, result = %s", converterClassName, String.valueOf(configured))); } } } catch (Exception e) { throw new FlumeException(String.format("Unable to create instance of converter %s", converterClassName), e); } String connectionFactoryName = context.getString(JMSSourceConfiguration.CONNECTION_FACTORY, JMSSourceConfiguration.CONNECTION_FACTORY_DEFAULT).trim(); assertNotEmpty(initialContextFactoryName, String.format("Initial Context Factory is empty. This is specified by %s", JMSSourceConfiguration.INITIAL_CONTEXT_FACTORY)); assertNotEmpty(providerUrl, String.format("Provider URL is empty. This is specified by %s", JMSSourceConfiguration.PROVIDER_URL)); assertNotEmpty(destinationName, String.format("Destination Name is empty. This is specified by %s", JMSSourceConfiguration.DESTINATION_NAME)); assertNotEmpty(destinationTypeName, String.format("Destination Type is empty. This is specified by %s", JMSSourceConfiguration.DESTINATION_TYPE)); try { destinationType = JMSDestinationType.valueOf(destinationTypeName); } catch (IllegalArgumentException e) { throw new FlumeException(String.format("Destination type '%s' is " + "invalid.", destinationTypeName), e); } try { destinationLocator = JMSDestinationLocator.valueOf(destinationLocatorName); } catch (IllegalArgumentException e) { throw new FlumeException( String.format("Destination locator '%s' is " + "invalid.", destinationLocatorName), e); } Preconditions.checkArgument(batchSize > 0, "Batch size must be greater than 0"); try { Properties contextProperties = new Properties(); contextProperties.setProperty(javax.naming.Context.INITIAL_CONTEXT_FACTORY, initialContextFactoryName); contextProperties.setProperty(javax.naming.Context.PROVIDER_URL, providerUrl); // Provide properties for connecting via JNDI if (this.userName.isPresent()) { contextProperties.setProperty(javax.naming.Context.SECURITY_PRINCIPAL, this.userName.get()); } if (this.password.isPresent()) { contextProperties.setProperty(javax.naming.Context.SECURITY_CREDENTIALS, this.password.get()); } initialContext = initialContextFactory.create(contextProperties); } catch (NamingException e) { throw new FlumeException(String.format("Could not create initial context %s provider %s", initialContextFactoryName, providerUrl), e); } try { connectionFactory = (ConnectionFactory) initialContext.lookup(connectionFactoryName); } catch (NamingException e) { throw new FlumeException("Could not lookup ConnectionFactory", e); } }
From source file:be.iminds.aiolos.cloud.jclouds.CloudManagerImplOpenStack.java
protected Template getTemplate() { // Default template chooses the smallest size on an operating system // that tested to work with java, which tends to be Ubuntu or CentOS TemplateBuilder templateBuilder = computeService.templateBuilder(); TemplateOptions options = new TemplateOptions().inboundPorts(inboundPorts); ImmutableList.Builder<Statement> bootstrapBuilder = ImmutableList.<Statement>builder(); if (imageId != null) templateBuilder.imageId(imageId); else//from w ww . ja v a 2s . c om Activator.logger.log(LogService.LOG_WARNING, String.format("No Image ID (%s) provided.", PROPERTY_IMAGE_ID)); if (minRam != null) templateBuilder.minRam(Integer.parseInt(minRam)); if (minCores != null) templateBuilder.minCores(Double.parseDouble(minCores)); if (minDisk != null) templateBuilder.minDisk(Double.parseDouble(minDisk)); if (publicKeyFile != null) { try { options.authorizePublicKey(Files.toString(publicKeyFile, StandardCharsets.UTF_8)); } catch (IOException e) { Activator.logger.log(LogService.LOG_ERROR, String.format("Public ssh key file (%s) does not exist.", publicKeyFile), e); } } if (networks != null) options.networks(networks); else Activator.logger.log(LogService.LOG_WARNING, String.format( "No network ID (%s) provided. If more than one network is available VM creation will fail.", PROPERTY_NETWORK_IDS)); if (adminAccess) bootstrapBuilder.add(AdminAccess.standard()); // Build the statement that will perform all the operations above StatementList bootstrap = new StatementList(bootstrapBuilder.build()); if (!bootstrap.isEmpty()) options.runScript(bootstrap); return templateBuilder.options(options).build(); }