io.advantageous.boon.core.IO.readLines()方法的使用及代码示例

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

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

IO.readLines介绍

暂无

代码示例

代码示例来源: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: com.github.advantageous/boon-reflekt

public static List<String> readLines( InputStream is ) {
  try ( Reader reader = new InputStreamReader( is, DEFAULT_CHARSET ) ) {
    return readLines( reader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

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

public static List<String> readLines( Reader reader ) {
  try ( BufferedReader bufferedReader = new BufferedReader( reader ) ) {
    return readLines( bufferedReader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

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

public static List<String> readLines( InputStream is ) {
  try ( Reader reader = new InputStreamReader( is, DEFAULT_CHARSET ) ) {
    return readLines( reader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

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

public static List<String> readLines( Reader reader ) {
  try ( BufferedReader bufferedReader = new BufferedReader( reader ) ) {
    return readLines( bufferedReader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

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

public static List<String> readLines( File file ) {
  try ( FileReader reader = new FileReader( file ) ) {
    return readLines( reader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

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

public static List<String> readLines( File file ) {
  try ( FileReader reader = new FileReader( file ) ) {
    return readLines( reader );
  } catch ( Exception ex ) {
    return Exceptions.handle( List.class, ex );
  }
}

代码示例来源:origin: com.github.advantageous/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: 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/qbit-service-discovery

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");
  }
}

相关文章