List of usage examples for org.apache.commons.io IOUtils toString
public static String toString(byte[] input, String encoding) throws IOException
byte[]
as a String using the specified character encoding. From source file:cop.maven.plugins.RamlMojoIT.java
private static String readResource(String name) throws IOException { return IOUtils.toString(RamlMojoIT.class.getResourceAsStream(name), "UTF-8"); }
From source file:com.nestlabs.sdk.StructureAndroidTest.java
@Test public void testStructureToParcel() { try {//from www . j a v a 2 s . c om String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_STRUCTURE_JSON), "utf-8"); Structure structure = mapper.readValue(json, Structure.class); Parcel parcel = Parcel.obtain(); structure.writeToParcel(parcel, 0); parcel.setDataPosition(0); Structure structureFromParcel = Structure.CREATOR.createFromParcel(parcel); assertEquals(structure, structureFromParcel); assertEquals(structureFromParcel.getStructureId(), "VqFabWH21nwVyd4RWgJgNb292wa7hG"); assertEquals(structureFromParcel.getThermostats().size(), 1); assertEquals(structureFromParcel.getThermostats().get(0), "peyiJNo0IldT2YlIVtYaGQ"); assertEquals(structureFromParcel.getSmokeCoAlarms().size(), 1); assertEquals(structureFromParcel.getSmokeCoAlarms().get(0), "RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs"); assertEquals(structureFromParcel.getCameras().size(), 1); assertEquals(structureFromParcel.getCameras().get(0), "awJo6rHX"); assertEquals(structureFromParcel.getDevices().size(), 1); assertEquals(structureFromParcel.getAway(), "home"); assertEquals(structureFromParcel.getName(), "Home"); assertEquals(structureFromParcel.getCountryCode(), "US"); assertEquals(structureFromParcel.getPostalCode(), "94304"); assertEquals(structureFromParcel.getPeakPeriodStartTime(), "2015-10-31T23:59:59.000Z"); assertEquals(structureFromParcel.getPeakPeriodEndTime(), "2015-10-31T23:59:59.000Z"); assertEquals(structureFromParcel.getTimeZone(), "America/Los_Angeles"); assertNotNull(structureFromParcel.getEta()); Structure.ETA eta = structureFromParcel.getEta(); assertEquals(eta.getTripId(), "myTripHome1024"); assertEquals(eta.getEstimatedArrivalWindowBegin(), "2015-10-31T22:42:59.000Z"); assertEquals(eta.getEstimatedArrivalWindowEnd(), "2015-10-31T23:59:59.000Z"); assertEquals(structureFromParcel.getRhrEnrollment(), true); assertNotNull(structureFromParcel.getWheres()); assertEquals(structureFromParcel.getWheres().size(), 1); Structure.Where where = structureFromParcel.getWheres().get("Fqp6wJIX"); assertNotNull(where); assertEquals(where.getWhereId(), "Fqp6wJIX"); assertEquals(where.getName(), "Bedroom"); } catch (IOException e) { e.printStackTrace(); Assert.fail(); } }
From source file:cop.raml.TestUtils.java
public static String getResourceAsString(String path) { try (InputStream in = TestUtils.class.getClassLoader().getResourceAsStream(path)) { return IOUtils.toString(in, StandardCharsets.UTF_8).trim(); } catch (Exception ignored) { return null; }/*from w w w .ja v a2s.c o m*/ }
From source file:io.gravitee.gateway.policy.CachedPolicyConfigurationFactoryTest.java
@Test public void createPolicyConfigurationFromCache() { try (InputStream is = PolicyConfigurationFactoryTest.class .getResourceAsStream("policy-configuration-01.json")) { String configuration = IOUtils.toString(is, "UTF-8"); DummyPolicyConfiguration policyConfiguration = policyConfigurationFactory .create(DummyPolicyConfiguration.class, configuration); DummyPolicyConfiguration policyConfiguration2 = policyConfigurationFactory .create(DummyPolicyConfiguration.class, configuration); Assert.assertNotNull(policyConfiguration); Assert.assertNotNull(policyConfiguration2); Assert.assertEquals(policyConfiguration, policyConfiguration2); } catch (IOException e) { e.printStackTrace();//from w w w . ja v a 2 s.c o m } }
From source file:com.nestlabs.sdk.StructureTest.java
@Test public void testCreateStructureWithJacksonMapper_shouldSetAllValuesCorrectly() { try {/*ww w . j a v a2 s.c om*/ String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_STRUCTURE_JSON), "utf-8"); Structure structure = mapper.readValue(json, Structure.class); assertEquals(structure.getStructureId(), "VqFabWH21nwVyd4RWgJgNb292wa7hG"); assertEquals(structure.getThermostats().size(), 1); assertEquals(structure.getThermostats().get(0), "peyiJNo0IldT2YlIVtYaGQ"); assertEquals(structure.getSmokeCoAlarms().size(), 1); assertEquals(structure.getSmokeCoAlarms().get(0), "RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs"); assertEquals(structure.getCameras().size(), 1); assertEquals(structure.getCameras().get(0), "awJo6rHX"); assertEquals(structure.getDevices().size(), 1); assertEquals(structure.getAway(), "home"); assertEquals(structure.getName(), "Home"); assertEquals(structure.getCountryCode(), "US"); assertEquals(structure.getPostalCode(), "94304"); assertEquals(structure.getPeakPeriodStartTime(), "2015-10-31T23:59:59.000Z"); assertEquals(structure.getPeakPeriodEndTime(), "2015-10-31T23:59:59.000Z"); assertEquals(structure.getTimeZone(), "America/Los_Angeles"); assertNotNull(structure.getEta()); Structure.ETA eta = structure.getEta(); assertEquals(eta.getTripId(), "myTripHome1024"); assertEquals(eta.getEstimatedArrivalWindowBegin(), "2015-10-31T22:42:59.000Z"); assertEquals(eta.getEstimatedArrivalWindowEnd(), "2015-10-31T23:59:59.000Z"); assertEquals(structure.getRhrEnrollment(), true); assertNotNull(structure.getWheres()); assertEquals(structure.getWheres().size(), 1); Structure.Where where = structure.getWheres().get("Fqp6wJIX"); assertNotNull(where); assertEquals(where.getWhereId(), "Fqp6wJIX"); assertEquals(where.getName(), "Bedroom"); } catch (IOException e) { e.printStackTrace(); Assert.fail(); } }
From source file:com.nestlabs.sdk.ThermostatTest.java
@Test public void testCreateThermostatWithJacksonMapper_shouldSetAllValuesCorrectly() { try {// w w w .j a v a 2 s .co m String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_THERMOSTAT_JSON), "utf-8"); Thermostat thermostat = mapper.readValue(json, Thermostat.class); assertEquals(thermostat.getDeviceId(), "peyiJNo0IldT2YlIVtYaGQ"); assertEquals(thermostat.getSoftwareVersion(), "4.0"); assertEquals(thermostat.getStructureId(), "VqFabWH21nwVyd4R..."); assertEquals(thermostat.getWhereId(), "UNCBGUnN24"); assertEquals(thermostat.getName(), "Hallway (upstairs)"); assertEquals(thermostat.getNameLong(), "Hallway Thermostat (upstairs)"); assertEquals(thermostat.isOnline(), true); assertEquals(thermostat.getLocale(), "en-US"); assertEquals(thermostat.getLastConnection(), "2015-10-31T23:59:59.000Z"); assertEquals(thermostat.getCanCool(), true); assertEquals(thermostat.getCanHeat(), true); assertEquals(thermostat.isUsingEmergencyHeat(), true); assertEquals(thermostat.getHasFan(), true); assertEquals(thermostat.getFanTimerActive(), true); assertEquals(thermostat.getFanTimerTimeout(), "2015-10-31T23:59:59.000Z"); assertEquals(thermostat.getHasLeaf(), true); assertEquals(thermostat.getTemperatureScale(), "C"); assertEquals(thermostat.getTargetTemperatureF(), 72); assertEquals(thermostat.getTargetTemperatureC(), 21.5, 0.01); assertEquals(thermostat.getTargetTemperatureHighF(), 72); assertEquals(thermostat.getTargetTemperatureHighC(), 21.5, 0.01); assertEquals(thermostat.getTargetTemperatureLowF(), 64); assertEquals(thermostat.getTargetTemperatureLowC(), 17.5, 0.01); assertEquals(thermostat.getAwayTemperatureHighF(), 72); assertEquals(thermostat.getAwayTemperatureHighC(), 21.5, 0.01); assertEquals(thermostat.getAwayTemperatureLowF(), 64); assertEquals(thermostat.getAwayTemperatureLowC(), 17.5, 0.01); assertEquals(thermostat.getHvacMode(), "heat"); assertEquals(thermostat.getAmbientTemperatureF(), 72); assertEquals(thermostat.getAmbientTemperatureC(), 21.5, 0.01); assertEquals(thermostat.getHumidity(), 40); assertEquals(thermostat.getHvacState(), "heating"); assertEquals(thermostat.isLocked(), true); assertEquals(thermostat.getLockedTempMinF(), "65"); assertEquals(thermostat.getLockedTempMaxF(), "80"); assertEquals(thermostat.getLockedTempMinC(), "19.5"); assertEquals(thermostat.getLockedTempMaxC(), "24.5"); assertEquals(thermostat.getLabel(), "upstairs"); } catch (IOException e) { e.printStackTrace(); Assert.fail(); } }
From source file:com.adaptris.core.config.DummyConfigurationPreProcessor.java
@Override public String process(URL urlToXml) throws CoreException { String xml = null;/* w w w .ja v a 2 s. c om*/ try (InputStream in = urlToXml.openStream()) { xml = IOUtils.toString(in, Charset.defaultCharset()); } catch (IOException e) { ExceptionHelper.rethrowCoreException(e); } return xml; }
From source file:com.twosigma.beaker.core.module.elfinder.impl.commands.GetCommand.java
@Override public void execute(FsService fsService, HttpServletRequest request, ServletContext servletContext, JSONObject json) throws Exception { String target = request.getParameter("target"); FsItemEx fsi = super.findItem(fsService, target); InputStream is = fsi.openInputStream(); String content = IOUtils.toString(is, "utf-8"); is.close();/*from w w w . j av a2 s .c o m*/ json.put("content", content); }
From source file:jfix.zk.Medias.java
public static String asString(Media media) { try {/* w ww. j a va 2 s. com*/ String result = null; if (media.isBinary()) { InputStream input = Medias.asStream(media); result = IOUtils.toString(input, "UTF-8"); input.close(); } else { Reader reader = Medias.asReader(media); result = IOUtils.toString(reader); reader.close(); } return result; } catch (Exception e) { throw new RuntimeException(e.getMessage(), e); } }
From source file:me.mast3rplan.phantombot.twitch.TwitchAPI.java
public JSONObject getObject(String url) throws IOException { URLConnection connection = new URL(url).openConnection(); connection.setUseCaches(false);/*from w w w .ja v a 2s . com*/ connection.setDefaultUseCaches(false); String content = IOUtils.toString(connection.getInputStream(), connection.getContentEncoding()); return new JSONObject(content); }