• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java IOUtils类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中spark.utils.IOUtils的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



IOUtils类属于spark.utils包,在下文中一共展示了IOUtils类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: buildByLatLong

import spark.utils.IOUtils; //导入依赖的package包/类
/**
 * Build City information by latitude and longitude
 * @param latlong [latitude,longitude]
 */
public void buildByLatLong(String[] latlong){
	try{
		//query attributes for openstreetmap
		//format = json 	 -> response should be in json
		//lat 				 -> set latitude
		//lon 				 -> set longitude
		//limit = 1 		 -> only want the most relevant location
		//addressdetails = 1 -> request detailed information
		//country = us 		 -> only look in the US
		String query = String.format("format=json&lat=%s&lon=%s&limit=1&addressdetails=1&country=us", URLEncoder.encode(latlong[0], charset), URLEncoder.encode(latlong[1], charset));
		URLConnection connection = new URL(reverse_url + "?" + query).openConnection(); //create request
		connection.setRequestProperty("Accepted-Charset", charset); //make sure we received the correct charset
		InputStream response = connection.getInputStream(); //receive input as input stream
		String in = IOUtils.toString(response); //turn response to string
		JsonObject jobject = new JsonParser().parse(in).getAsJsonObject(); //use gson to parse string response
		JsonObject address = jobject.getAsJsonObject("address");
		zip = address.get("postcode").getAsString(); //store zip code
		name = address.get("city").getAsString();    //store city name
		state = address.get("state").getAsString();  //store state name
	}
	catch (Exception e){ //catch errors
		e.printStackTrace();
	}
}
 
开发者ID:teovoinea,项目名称:GLIFRP,代码行数:29,代码来源:OpenStreetMapWrapper.java


示例2: reloadConfig

import spark.utils.IOUtils; //导入依赖的package包/类
private void reloadConfig() throws IOException {
    checkConfigDir();

    Path configFile = Paths.get(configDir + "/config.conf");

    if (Files.notExists(configFile)) {
        InputStream defaultConfig = getClass().getResourceAsStream("defaultConfig.conf");

        try (FileWriter writer = new FileWriter(configFile.toFile())) {
            IOUtils.copy(defaultConfig, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    ConfigurationLoader<CommentedConfigurationNode> loader = HoconConfigurationLoader.builder().setPath(configFile).build();

    rootNode = loader.load();
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:20,代码来源:SpongeUniversalMinecraftAPI.java


示例3: reloadUserConfig

import spark.utils.IOUtils; //导入依赖的package包/类
private void reloadUserConfig() throws IOException {
    checkConfigDir();

    Path usersConfigFile = Paths.get(configDir + "/users.conf");

    if (Files.notExists(usersConfigFile)) {
        InputStream defaultConfig = getClass().getResourceAsStream("defaultUsers.conf");

        try (FileWriter writer = new FileWriter(usersConfigFile.toFile())) {
            IOUtils.copy(defaultConfig, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    ConfigurationLoader<CommentedConfigurationNode> usersLoader = HoconConfigurationLoader.builder().setPath(usersConfigFile).build();

    usersNode = usersLoader.load();
}
 
开发者ID:UniversalMinecraftAPI,项目名称:UniversalMinecraftAPI,代码行数:20,代码来源:SpongeUniversalMinecraftAPI.java


示例4: request

import spark.utils.IOUtils; //导入依赖的package包/类
private TestResponse request(String method, String path) {
try {
    // FIXME this should work in a CI environment if possible
    URL url = new URL("http://localhost:4567" + path);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
    connection.setRequestMethod(method);
    connection.setDoOutput(true);
    connection.connect();
    String body = IOUtils.toString(connection.getInputStream());
    return new TestResponse(connection.getResponseCode(), body);
} catch (IOException e) {
    e.printStackTrace();
    fail("Sending request failed: " + e.getMessage());
    return null;
}
   }
 
开发者ID:unitsofmeasurement,项目名称:uom-demos,代码行数:17,代码来源:MeasurementControllerIntegrationTest.java


示例5: fileContent

import spark.utils.IOUtils; //导入依赖的package包/类
@VisibleForTesting
static String fileContent(String location) {
  try {
    InputStream reader = Viewer.class.getResourceAsStream(location);
    return IOUtils.toString(reader);
  } catch (Exception e) {
    LOGGER.error("Unable to read file at location: " + location + ".", e);
  }
  return "// Unable to read file at location:\n// \"" + location + "\"\n";
}
 
开发者ID:SonarSource,项目名称:source-graph-viewer,代码行数:11,代码来源:Viewer.java


示例6: getOpenIDConfiguration

import spark.utils.IOUtils; //导入依赖的package包/类
/**
 * Fetches the Google's OpenID configuration and parses
 * it the fields we care about (currently only one)
 * @return a new OpenIDConfiguration object that contains the URL from which we can fetch Google's public keys
 * @throws IOException when something goes wrong with with fetching the data
 */
public OpenIDConfiguration getOpenIDConfiguration() throws IOException {
    try {
        InputStream in = new URL(googleOpenIDConfigurationEndpoint).openStream();
        return gson.fromJson(IOUtils.toString(in),OpenIDConfiguration.class);
    } catch (MalformedURLException e) {
        System.out.println("Your dev is an idiot. Authentication will fail because we could not verify Google's signatures.");
        return null;
    }
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-4-dorfner-v2,代码行数:16,代码来源:Auth.java


示例7: buildByZip

import spark.utils.IOUtils; //导入依赖的package包/类
/**
 * Build City Information by Zip Code
 * @param zip_code Zip Code of location
 */
public void buildByZip(String zip_code){
	try{
		//query attributes for openstreetmap
		//postalcode 		  -> zipcode to search for
		//countrycodes = us   -> only look in the US
		//limit = 1 		  -> only want the most relevant location
		//addressdetails = 1  -> request detailed information
		//format = json 	  -> response should be in json
		//polygon_geojson = 1 -> for extensibility if we want to make polygons from json
		//country = us 		  -> only look in the US
		String query = String.format("postalcode=%s&countrycodes=us&limit=1&addressdetails=1&format=json&polygon_geojson=1&country=us",URLEncoder.encode(zip_code, charset));
		URLConnection connection = new URL(search_url + "?" + query).openConnection(); //create request
		connection.setRequestProperty("Accepted-Charset", charset); //make sure we received the correct charset
		InputStream response = connection.getInputStream(); //receive input as input stream
		String in = IOUtils.toString(response); //turn response to string
		JsonArray jarray = (JsonArray) new JsonParser().parse(in); //use gson to parse string response
		JsonObject jobject = jarray.get(0).getAsJsonObject(); //get the first element (most relevant & should be only element because limit=1)
		String[] res = {jobject.get("lat").getAsString(), jobject.get("lon").getAsString()}; //parse latitude and longitude into a string array
		//System.out.println("Found lat: " + res[0] + " and lon: " + res[1] + " from zip code: " + zip_code);
		lat = res[0]; //store lat
		lon = res[1]; //store lon
		JsonObject address = jobject.getAsJsonObject("address");
		name = address.get("city").getAsString(); //store city name
		state = address.get("state").getAsString(); //store state name
	}
	catch (Exception e){ //catch errors
		e.printStackTrace();
	}
}
 
开发者ID:teovoinea,项目名称:GLIFRP,代码行数:34,代码来源:OpenStreetMapWrapper.java


示例8: buildByCityState

import spark.utils.IOUtils; //导入依赖的package包/类
/**
 * Build City information by city name and city state
 * @param city_name Name of city
 * @param city_state Name of state
 */
public void buildByCityState(String city_name, String city_state){
	try{
		//query attributes for openstreetmap
		//format = json 	 -> response should be in json
		//city 				 -> name of city
		//state 			 -> name of state
		//limit = 1 		 -> only want the most relevant location
		//addressdetails = 1 -> request detailed information
		//country = us 		 -> only look in the US
		String query = String.format("city=%s&state=%s&limit=1&addressdetails=1&format=json&country=us", URLEncoder.encode(city_name, charset), URLEncoder.encode(city_state, charset));
		URLConnection connection = new URL(search_url + "?" + query).openConnection(); //create request
		connection.setRequestProperty("Accepted-Charset", charset); //make sure we received the correct charset
		InputStream response = connection.getInputStream(); //receive input as input stream
		String in  = IOUtils.toString(response); //turn response to string
		JsonArray jarray = (JsonArray) new JsonParser().parse(in); //use gson to parse string response
		JsonObject jobject = jarray.get(0).getAsJsonObject();
		lat = jobject.get("lat").getAsString(); //store lat
		lon = jobject.get("lon").getAsString(); //store lon
		//JsonObject address = jobject.getAsJsonObject("address");
		//name = address.get("city").getAsString();//store city
		//state = address.get("state").getAsString();//store state
	}
	catch (Exception e){ //catch errors
		e.printStackTrace();
	}
}
 
开发者ID:teovoinea,项目名称:GLIFRP,代码行数:32,代码来源:OpenStreetMapWrapper.java


示例9: executeRequest

import spark.utils.IOUtils; //导入依赖的package包/类
private static String executeRequest(String method, String path) throws IOException {
  URL url = new URL("http://localhost:8080" + path);
  HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  connection.setRequestMethod(method);
  connection.setDoOutput(true);
  connection.connect();
  return IOUtils.toString(connection.getInputStream());
}
 
开发者ID:GoogleCloudPlatform,项目名称:java-docs-samples,代码行数:9,代码来源:UserControllerTest.java


示例10: read

import spark.utils.IOUtils; //导入依赖的package包/类
private String read(String subPath) {
    try {
        return IOUtils.toString(new URI("http://localhost:8501/"+subPath).toURL().openStream());
    } catch (IOException | URISyntaxException e) {
        throw new RuntimeException("Got exception", e);
    }
}
 
开发者ID:amedia,项目名称:regurgitator,代码行数:8,代码来源:Consumer.java


示例11: doFilter

import spark.utils.IOUtils; //导入依赖的package包/类
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws
        IOException,
        ServletException {
    HttpServletRequest httpRequest = (HttpServletRequest) request; // NOSONAR

    final String relativePath = FilterTools.getRelativePath(httpRequest, filterPath);

    if (LOG.isDebugEnabled()) {
        LOG.debug(relativePath);
    }

    HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(httpRequest) {
        @Override
        public String getRequestURI() {
            return relativePath;
        }
    };

    // handle static resources
    if (staticResourceHandlers != null) {
        for (AbstractResourceHandler staticResourceHandler : staticResourceHandlers) {
            AbstractFileResolvingResource resource = staticResourceHandler.getResource(httpRequest);
            if (resource != null && resource.isReadable()) {
                IOUtils.copy(resource.getInputStream(), response.getWriter());
                return;
            }
        }
    }

    matcherFilter.doFilter(requestWrapper, response, chain);
}
 
开发者ID:rodolfodpk,项目名称:spark-guice,代码行数:33,代码来源:SparkGuiceFilter.java


示例12: SocketIO

import spark.utils.IOUtils; //导入依赖的package包/类
public SocketIO(SocketIOSessions sessions) {
    String content;
    InputStream resource = getClass().getResourceAsStream("/socket.io.js");
    try {
        byte[] bytes = IOUtils.toByteArray(resource);
        content = new String(bytes);
    } catch (IOException e) {
        content = null;
        LOG.error("Could not load socket.io.js content", e);
    }
    socketIOJS = content;
    this.sessions = sessions;
}
 
开发者ID:javaBin,项目名称:Switcharoo,代码行数:14,代码来源:SocketIO.java


示例13: handle

import spark.utils.IOUtils; //导入依赖的package包/类
@Override
public Object handle(Request request, Response response) throws Exception {
	String name = request.params("name");
	if ( ! db().existsComponent(name) ) {
		return requestInvalid(response, "Component not exists");
	}
	
	db().retrieveComponent(name, (is) -> {
		response.type("application/binary");
		
		ServletOutputStream os;
		try {
			os = response.raw().getOutputStream();
			org.apache.commons.io.IOUtils.copy(is, os);
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		
		/*
		try {
			byte array[] = IOUtils.toByteArray(is);
			response.body(String.valueOf(array));
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		*/
		return true;
	});
	
	return requestOk(response, null);
}
 
开发者ID:jesusc,项目名称:bento,代码行数:35,代码来源:ComponentGET.java


示例14: request

import spark.utils.IOUtils; //导入依赖的package包/类
protected TestResponse request(String method, String path, String body,boolean isByteArray)
{

	try
	{
		URL url = new URL("http://localhost:4567" + path);
		HttpURLConnection connection = (HttpURLConnection) url
				.openConnection();
		connection.setRequestMethod(method);

		connection.setDoOutput(true);
		connection.connect();

		//connection.setRequestProperty("Content-Type","application/json");  
	    
		if(body != null)
		{
		byte[] outputInBytes = body.getBytes("UTF-8");
		OutputStream os = connection.getOutputStream();
		os.write( outputInBytes );    
		os.close();
		}
		
		if(isByteArray)
		{
			byte[] responseBodyByteArray = IOUtils.toByteArray(connection.getInputStream());
			return new TestResponse(connection.getResponseCode(), responseBodyByteArray);
		}
		else
		{
			String responseBody = IOUtils.toString(connection.getInputStream());
			return new TestResponse(connection.getResponseCode(), responseBody);
		}
		
		
	

	} catch (IOException e)
	{
		e.printStackTrace();
		fail("Sending request failed: " + e.getMessage());
		return null;
	}

}
 
开发者ID:rodrigoEclipsa,项目名称:excelToApp,代码行数:46,代码来源:TestBase.java



注:本文中的spark.utils.IOUtils类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ActivityController类代码示例发布时间:2022-05-21
下一篇:
Java NotFoundException类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap