io.advantageous.boon.core.IO类的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(6.6k)|赞(0)|评价(0)|浏览(214)

本文整理了Java中io.advantageous.boon.core.IO类的一些代码示例,展示了IO类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。IO类的具体详情如下:
包路径:io.advantageous.boon.core.IO
类名称:IO

IO介绍

暂无

代码示例

代码示例来源:origin: advantageous/qbit

  1. private static String readErrorResponseBodyDoNotDie(HttpURLConnection http, int status, String charset) {
  2. InputStream errorStream = http.getErrorStream();
  3. if (errorStream != null) {
  4. String error = charset == null ? IO.read(errorStream) :
  5. IO.read(errorStream, charset);
  6. return error;
  7. } else {
  8. return "";
  9. }
  10. }

代码示例来源:origin: advantageous/qbit

  1. private static URLConnection doPost(String url, Map<String, ?> headers,
  2. String contentType, String charset, String body
  3. ) throws IOException {
  4. HttpURLConnection connection;/* Handle output. */
  5. connection = (HttpURLConnection) new URL(url).openConnection();
  6. connection.setConnectTimeout(DEFAULT_TIMEOUT_SECONDS * 1000);
  7. connection.setDoOutput(true);
  8. manageContentTypeHeaders(contentType, charset, connection);
  9. manageHeaders(headers, connection);
  10. IO.write(connection.getOutputStream(), body, IO.DEFAULT_CHARSET);
  11. return connection;
  12. }

代码示例来源:origin: advantageous/qbit

  1. private static byte[] readResponseBodyAsBytes(HttpURLConnection http) {
  2. try {
  3. return IO.input(http.getInputStream());
  4. } catch (IOException e) {
  5. return Exceptions.handle(byte[].class, e);
  6. }
  7. }

代码示例来源:origin: advantageous/qbit

  1. puts(httpResponse.contentType());
  2. .setBinaryReceiver((code, contentType, body) -> {
  3. puts(body.length, code, contentType);
  4. IO.write(thisImage.toPath(), body);
  5. })
  6. .build();
  7. serverRequest.getReceiver().response(200, "image/jpeg", IO.input(thisImage.getAbsolutePath()));
  8. });

代码示例来源:origin: advantageous/qbit

  1. @Override
  2. public void servicesRemoved(String serviceName, int count) {
  3. puts("servicesRemoved", serviceName, count);
  4. }
  5. };

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static void output( String file, byte[] bytes ) {
  2. IO.write( path(file), bytes );
  3. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static String readChild( Path parentDir, String childFileName ) {
  2. try {
  3. final Path newFilePath = path( parentDir.toString(),
  4. childFileName );
  5. return read( newFilePath );
  6. } catch ( Exception ex ) {
  7. return Exceptions.handle( String.class, ex );
  8. }
  9. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static byte[] input( String fileName ) {
  2. try {
  3. return input( Files.newInputStream( path(fileName) ) );
  4. } catch ( IOException e ) {
  5. return Exceptions.handle( byte[].class, e );
  6. }
  7. }

代码示例来源:origin: advantageous/qbit

  1. public static List<URI> readDnsConf() {
  2. final Logger logger = LoggerFactory.getLogger(DnsUtil.class);
  3. final boolean debug = logger.isDebugEnabled();
  4. final File file = new File(Sys.sysProp(QBIT_DNS_RESOLV_CONF, "/etc/resolv.conf"));
  5. if (file.exists()) {
  6. final List<String> lines = IO.readLines(file);
  7. if (debug) logger.debug("file contents {}", lines);
  8. return lines.stream().filter(line -> line.startsWith("nameserver"))
  9. .map(line ->
  10. {
  11. if (debug) logger.debug("file content line = {}", line);
  12. final String uriToParse = line.replace("nameserver ", "").trim();
  13. final String[] split = Str.split(uriToParse, ':');
  14. try {
  15. if (split.length == 1) {
  16. return new URI("dns", "", split[0], 53, "", "", "");
  17. } else if (split.length >= 2) {
  18. return new URI("dns", "", split[0], Integer.parseInt(split[1]), "", "", "");
  19. } else {
  20. throw new IllegalStateException("Unable to parse URI from /etc/resolv.conf");
  21. }
  22. } catch (URISyntaxException e) {
  23. throw new IllegalStateException("failed to convert to URI");
  24. }
  25. })
  26. .collect(Collectors.toList());
  27. } else {
  28. throw new IllegalStateException("" + file + " not found");
  29. }
  30. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. private static List<String> readLines( String location, URI uri ) throws Exception {
  2. try {
  3. String path = location;
  4. path = getWindowsPathIfNeeded( path );
  5. FileSystem fileSystem = FileSystems.getFileSystem( uri );
  6. Path fsPath = fileSystem.getPath( path );
  7. //Paths.get()
  8. return Files.readAllLines( fsPath, DEFAULT_CHARSET );
  9. } catch ( ProviderNotFoundException ex ) {
  10. return readLines( uri.toURL().openStream() );
  11. }
  12. }

代码示例来源:origin: com.github.advantageous/boon-reflekt

  1. @Override
  2. public Path apply( String s ) {
  3. return path(s);
  4. }
  5. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static List<String> list( final String path ) {
  2. final Path pathFromFileSystem = path(path);
  3. return list( pathFromFileSystem );
  4. }

代码示例来源:origin: io.advantageous.boon/boon-util

  1. private static void pathsFromFileSystem( List<Path> resourcePaths, URL u ) {
  2. URI fileURI = IO.createURI( u.toString() );
  3. add( resourcePaths, IO.uriToPath( fileURI ) );
  4. }

代码示例来源:origin: com.github.advantageous/boon-reflekt

  1. public static String read( final String location ) {
  2. final URI uri = createURI( location );
  3. return Exceptions.tryIt( String.class, new Exceptions.TrialWithReturn<String>() {
  4. @Override
  5. public String tryIt() throws Exception {
  6. String path = location;
  7. path = getWindowsPathIfNeeded( path );
  8. if ( uri.getScheme() == null ) {
  9. Path thePath = FileSystems.getDefault().getPath( path );
  10. return read( Files.newBufferedReader( thePath, DEFAULT_CHARSET ) );
  11. } else if ( uri.getScheme().equals( FILE_SCHEMA ) ) {
  12. return readFromFileSchema( uri );
  13. } else {
  14. return read( location, uri );
  15. }
  16. }
  17. } );
  18. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static Path createDirectory( String dir ) {
  2. try {
  3. final Path newDir = path(dir);
  4. createDirectory( newDir );
  5. return newDir;
  6. } catch ( Exception ex ) {
  7. return Exceptions.handle( Path.class, ex );
  8. }
  9. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static List<String> readLines( final String location ) {
  2. final String path = getWindowsPathIfNeeded( location );
  3. final URI uri = createURI( path );
  4. return ( List<String> ) Exceptions.tryIt( Typ.list, new Exceptions.TrialWithReturn<List>() {
  5. @Override
  6. public List<String> tryIt() throws Exception {
  7. if ( uri.getScheme() == null ) {
  8. Path thePath = FileSystems.getDefault().getPath( path );
  9. return Files.readAllLines( thePath, DEFAULT_CHARSET );
  10. } else if ( uri.getScheme().equals( FILE_SCHEMA ) ) {
  11. Path thePath = FileSystems.getDefault().getPath( uri.getPath() );
  12. return Files.readAllLines( thePath, DEFAULT_CHARSET );
  13. } else {
  14. return readLines( location, uri );
  15. }
  16. }
  17. } );
  18. }

代码示例来源:origin: io.advantageous.boon/boon-reflekt

  1. public static List<String> listByExt( final String path, String ext ) {
  2. final List<String> list = list( path );
  3. final List<String> newList = new ArrayList<>();
  4. for ( String file : list ) {
  5. if ( file.endsWith( ext ) ) {
  6. newList.add( file );
  7. }
  8. }
  9. return newList;
  10. }

代码示例来源:origin: advantageous/qbit

  1. @Override
  2. public void accept(Long integer) {
  3. puts("Last ten second count for abc.count", integer);
  4. }
  5. }, "abc.count");

代码示例来源:origin: com.github.advantageous/boon-reflekt

  1. public static void write( String file, byte[] contents ) {
  2. write (path(file), contents);
  3. }

代码示例来源:origin: com.github.advantageous/boon-reflekt

  1. public static String readChild( Path parentDir, String childFileName ) {
  2. try {
  3. final Path newFilePath = path( parentDir.toString(),
  4. childFileName );
  5. return read( newFilePath );
  6. } catch ( Exception ex ) {
  7. return Exceptions.handle( String.class, ex );
  8. }
  9. }

相关文章