本文整理了Java中io.advantageous.boon.core.IO
类的一些代码示例,展示了IO
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IO
类的具体详情如下:
包路径:io.advantageous.boon.core.IO
类名称:IO
暂无
代码示例来源:origin: advantageous/qbit
private static String readErrorResponseBodyDoNotDie(HttpURLConnection http, int status, String charset) {
InputStream errorStream = http.getErrorStream();
if (errorStream != null) {
String error = charset == null ? IO.read(errorStream) :
IO.read(errorStream, charset);
return error;
} else {
return "";
}
}
代码示例来源:origin: advantageous/qbit
private static URLConnection doPost(String url, Map<String, ?> headers,
String contentType, String charset, String body
) throws IOException {
HttpURLConnection connection;/* Handle output. */
connection = (HttpURLConnection) new URL(url).openConnection();
connection.setConnectTimeout(DEFAULT_TIMEOUT_SECONDS * 1000);
connection.setDoOutput(true);
manageContentTypeHeaders(contentType, charset, connection);
manageHeaders(headers, connection);
IO.write(connection.getOutputStream(), body, IO.DEFAULT_CHARSET);
return connection;
}
代码示例来源:origin: advantageous/qbit
private static byte[] readResponseBodyAsBytes(HttpURLConnection http) {
try {
return IO.input(http.getInputStream());
} catch (IOException e) {
return Exceptions.handle(byte[].class, e);
}
}
代码示例来源:origin: advantageous/qbit
puts(httpResponse.contentType());
.setBinaryReceiver((code, contentType, body) -> {
puts(body.length, code, contentType);
IO.write(thisImage.toPath(), body);
})
.build();
serverRequest.getReceiver().response(200, "image/jpeg", IO.input(thisImage.getAbsolutePath()));
});
代码示例来源:origin: advantageous/qbit
@Override
public void servicesRemoved(String serviceName, int count) {
puts("servicesRemoved", serviceName, count);
}
};
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static void output( String file, byte[] bytes ) {
IO.write( path(file), bytes );
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static String readChild( Path parentDir, String childFileName ) {
try {
final Path newFilePath = path( parentDir.toString(),
childFileName );
return read( newFilePath );
} catch ( Exception ex ) {
return Exceptions.handle( String.class, ex );
}
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static byte[] input( String fileName ) {
try {
return input( Files.newInputStream( path(fileName) ) );
} catch ( IOException e ) {
return Exceptions.handle( byte[].class, e );
}
}
代码示例来源:origin: advantageous/qbit
public static List<URI> readDnsConf() {
final Logger logger = LoggerFactory.getLogger(DnsUtil.class);
final boolean debug = logger.isDebugEnabled();
final File file = new File(Sys.sysProp(QBIT_DNS_RESOLV_CONF, "/etc/resolv.conf"));
if (file.exists()) {
final List<String> lines = IO.readLines(file);
if (debug) logger.debug("file contents {}", lines);
return lines.stream().filter(line -> line.startsWith("nameserver"))
.map(line ->
{
if (debug) logger.debug("file content line = {}", line);
final String uriToParse = line.replace("nameserver ", "").trim();
final String[] split = Str.split(uriToParse, ':');
try {
if (split.length == 1) {
return new URI("dns", "", split[0], 53, "", "", "");
} else if (split.length >= 2) {
return new URI("dns", "", split[0], Integer.parseInt(split[1]), "", "", "");
} else {
throw new IllegalStateException("Unable to parse URI from /etc/resolv.conf");
}
} catch (URISyntaxException e) {
throw new IllegalStateException("failed to convert to URI");
}
})
.collect(Collectors.toList());
} else {
throw new IllegalStateException("" + file + " not found");
}
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
private static List<String> readLines( String location, URI uri ) throws Exception {
try {
String path = location;
path = getWindowsPathIfNeeded( path );
FileSystem fileSystem = FileSystems.getFileSystem( uri );
Path fsPath = fileSystem.getPath( path );
//Paths.get()
return Files.readAllLines( fsPath, DEFAULT_CHARSET );
} catch ( ProviderNotFoundException ex ) {
return readLines( uri.toURL().openStream() );
}
}
代码示例来源:origin: com.github.advantageous/boon-reflekt
@Override
public Path apply( String s ) {
return path(s);
}
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static List<String> list( final String path ) {
final Path pathFromFileSystem = path(path);
return list( pathFromFileSystem );
}
代码示例来源:origin: io.advantageous.boon/boon-util
private static void pathsFromFileSystem( List<Path> resourcePaths, URL u ) {
URI fileURI = IO.createURI( u.toString() );
add( resourcePaths, IO.uriToPath( fileURI ) );
}
代码示例来源:origin: com.github.advantageous/boon-reflekt
public static String read( final String location ) {
final URI uri = createURI( location );
return Exceptions.tryIt( String.class, new Exceptions.TrialWithReturn<String>() {
@Override
public String tryIt() throws Exception {
String path = location;
path = getWindowsPathIfNeeded( path );
if ( uri.getScheme() == null ) {
Path thePath = FileSystems.getDefault().getPath( path );
return read( Files.newBufferedReader( thePath, DEFAULT_CHARSET ) );
} else if ( uri.getScheme().equals( FILE_SCHEMA ) ) {
return readFromFileSchema( uri );
} else {
return read( location, uri );
}
}
} );
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static Path createDirectory( String dir ) {
try {
final Path newDir = path(dir);
createDirectory( newDir );
return newDir;
} catch ( Exception ex ) {
return Exceptions.handle( Path.class, ex );
}
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static List<String> readLines( final String location ) {
final String path = getWindowsPathIfNeeded( location );
final URI uri = createURI( path );
return ( List<String> ) Exceptions.tryIt( Typ.list, new Exceptions.TrialWithReturn<List>() {
@Override
public List<String> tryIt() throws Exception {
if ( uri.getScheme() == null ) {
Path thePath = FileSystems.getDefault().getPath( path );
return Files.readAllLines( thePath, DEFAULT_CHARSET );
} else if ( uri.getScheme().equals( FILE_SCHEMA ) ) {
Path thePath = FileSystems.getDefault().getPath( uri.getPath() );
return Files.readAllLines( thePath, DEFAULT_CHARSET );
} else {
return readLines( location, uri );
}
}
} );
}
代码示例来源:origin: io.advantageous.boon/boon-reflekt
public static List<String> listByExt( final String path, String ext ) {
final List<String> list = list( path );
final List<String> newList = new ArrayList<>();
for ( String file : list ) {
if ( file.endsWith( ext ) ) {
newList.add( file );
}
}
return newList;
}
代码示例来源:origin: advantageous/qbit
@Override
public void accept(Long integer) {
puts("Last ten second count for abc.count", integer);
}
}, "abc.count");
代码示例来源:origin: com.github.advantageous/boon-reflekt
public static void write( String file, byte[] contents ) {
write (path(file), contents);
}
代码示例来源:origin: com.github.advantageous/boon-reflekt
public static String readChild( Path parentDir, String childFileName ) {
try {
final Path newFilePath = path( parentDir.toString(),
childFileName );
return read( newFilePath );
} catch ( Exception ex ) {
return Exceptions.handle( String.class, ex );
}
}
内容来源于网络,如有侵权,请联系作者删除!