org.javalite.common.Util.read()方法的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.8k)|赞(0)|评价(0)|浏览(177)

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

Util.read介绍

[英]Reads file into a byte array.
[中]将文件读入字节数组。

代码示例

代码示例来源:origin: javalite/activejdbc

/**
 * Reads contents of the input stream fully and returns it as String. Sets UTF-8 encoding internally.
 *
 * @param in InputStream to read from.
 * @return contents of the input stream fully as String.
 * @throws IOException in case of IO error
 */
public static String read(InputStream in) throws IOException {
  return read(in, "UTF-8");
}

代码示例来源:origin: javalite/activejdbc

/**
 * Reads contents of file fully and returns as string.
 *
 * @param fileName file name.
 * @param charset name of supported charset.
 * @return contents of entire file.
 */
public static String readFile(String fileName, String charset) {
  FileInputStream in = null;
  try {
    in = new FileInputStream(fileName);
    return read(in, charset);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(in);
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Reads contents of resource fully into a string.
 *
 * @param resourceName resource name.
 * @param charset name of supported charset
 * @return entire contents of resource as string.
 */
public static String readResource(String resourceName, String charset) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return read(is, charset);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: javalite/activejdbc

private static String exec(String command) {

    Runtime runtime = Runtime.getRuntime();

    try {

      Process p = runtime.exec(command);
      String output = read(p.getInputStream());
      String error = read(p.getErrorStream());

      if (!blank(error)) {
        throw new ExecException(error);
      }
      return output;
    } catch (ExecException e) {
      throw e;
    } catch (Exception e) {
      throw new ExecException(e);
    }
  }
}

代码示例来源:origin: javalite/activejdbc

private boolean loadStaticMetadata() {
  try {
    Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources("activejdbc_metadata.json");
    staticMetadataStatus = urls.hasMoreElements() ? STATIC_METADATA_LOADED : STATIC_METADATA_CHECKED;
    while(urls.hasMoreElements()) {
      URL url = urls.nextElement();
      LogFilter.log(LOGGER, LogLevel.INFO, "Loading metadata from: {}", url.toExternalForm());
      metaModels.fromJSON(Util.read(url.openStream()));
    }
    return staticMetadataStatus == STATIC_METADATA_LOADED;
  } catch(IOException e) {
    throw new InitException(e);
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Fetches response content from server as String.
 *
 * @return response content from server as String.
 */
public String text() {
  try {
    connect();
    return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream());
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }finally {
    dispose();
  }
}

代码示例来源:origin: javalite/activejdbc

/**
 * Fetches response content from server as String.
 *
 * @param encoding - name of supported charset to apply when reading data.
 *
 * @return response content from server as String.
 */
public String text(String encoding) {
  try {
    connect();
    return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding);
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }finally {
    dispose();
  }
}

代码示例来源:origin: javalite/activejdbc

private static synchronized Map<String, Set<String>> getModelMap() {
  if (modelMap == null) {
    try {
      modelMap = new HashMap<>();
      Enumeration<URL> urls = Registry.instance().getClass().getClassLoader().getResources("activejdbc_models.properties");
      while(urls.hasMoreElements()) {
        URL url = urls.nextElement();
        LogFilter.log(LOGGER, LogLevel.INFO, "Loading models from: {}", url.toExternalForm());
        String modelsFile = Util.read(url.openStream());
        String[] lines = Util.split(modelsFile, System.getProperty("line.separator"));
        for(String line : lines) {
          String[] parts = Util.split(line, ':');
          String modelName = parts[0];
          String dbName = parts[1];
          Set<String> modelNames = modelMap.computeIfAbsent(dbName, k -> new HashSet<>());
          if (!modelNames.add(modelName)) {
            throw new InitException(String.format("Model '{}' already exists for database '{}'", modelName, dbName));
          }
        }
      }
    } catch(IOException e) {
      throw new InitException(e);
    }
  }
  return modelMap;
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Reads contents of the input stream fully and returns it as String. Sets UTF-8 encoding internally.
 *
 * @param in InputStream to read from.
 * @return contents of the input stream fully as String.
 * @throws IOException in case of IO error
 */
public static String read(InputStream in) throws IOException {
  return read(in, "UTF-8");
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Reads contents of the input stream fully and returns it as String. Sets UTF-8 encoding internally.
 *
 * @param in InputStream to read from.
 * @return contents of the input stream fully as String.
 * @throws IOException in case of IO error
 */
public static String read(InputStream in) throws IOException {
  return read(in, "UTF-8");
}

代码示例来源:origin: javalite/activeweb

public String lessc(File lessFile) throws IOException, InterruptedException {
  logInfo("Executing: " + "lessc " + lessFile.getPath());
  String exec = "lessc";
  if (System.getProperty("os.name").toLowerCase().contains("windows")) {
    exec += ".cmd";
  }
  Process process = getRuntime().exec(new String[]{exec, lessFile.getPath()});
  String css = read(process.getInputStream(), "UTF-8");
  String error = read(process.getErrorStream(), "UTF-8");
  if (process.waitFor() != 0) {
    throw new RuntimeException(error);
  }
  return css;
}

代码示例来源:origin: javalite/activeweb

/**
 * Reads entire request data as String. Do not use for large data sets to avoid
 * memory issues, instead use {@link #getRequestInputStream()}.
 *
 * @return data sent by client as string.
 * @throws IOException
 */
protected String getRequestString() throws IOException {
  return Util.read(RequestContext.getHttpRequest().getInputStream());
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Reads contents of resource fully into a string.
 *
 * @param resourceName resource name.
 * @param charset name of supported charset
 * @return entire contents of resource as string.
 */
public static String readResource(String resourceName, String charset) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return read(is, charset);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Reads contents of resource fully into a string.
 *
 * @param resourceName resource name.
 * @param charset name of supported charset
 * @return entire contents of resource as string.
 */
public static String readResource(String resourceName, String charset) {
  InputStream is = Util.class.getResourceAsStream(resourceName);
  try {
    return read(is, charset);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(is);
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Reads contents of file fully and returns as string.
 *
 * @param fileName file name.
 * @param charset name of supported charset.
 * @return contents of entire file.
 */
public static String readFile(String fileName, String charset) {
  FileInputStream in = null;
  try {
    in = new FileInputStream(fileName);
    return read(in, charset);
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    closeQuietly(in);
  }
}

代码示例来源:origin: javalite/activeweb

/**
 * Converts entire content of this item to String.
 *
 * @return content streamed from this field as string.
 */
public String getStreamAsString(){
  try {
    return Util.read(fileItemStream.openStream());
  } catch (Exception e) {
    throw new ControllerException(e);
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Fetches response content from server as String.
 *
 * @return response content from server as String.
 */
public String text() {
  try {
    connect();
    return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream());
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }finally {
    dispose();
  }
}

代码示例来源:origin: org.javalite/javalite-common

/**
 * Fetches response content from server as String.
 *
 * @param encoding - name of supported charset to apply when reading data.
 *
 * @return response content from server as String.
 */
public String text(String encoding) {
  try {
    connect();
    return responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding);
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }finally {
    dispose();
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Fetches response content from server as String.
 *
 * @return response content from server as String.
 */
public String text() {
  try {
    connect();
    String result = responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream());
    dispose();
    return result;
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }
}

代码示例来源:origin: com.github.tchoulihan/javalite-common

/**
 * Fetches response content from server as String.
 *
 * @param encoding - name of supported charset to apply when reading data.
 *
 * @return response content from server as String.
 */
public String text(String encoding) {
  try {
    connect();
    String result = responseCode() >= 400 ? read(connection.getErrorStream()) : read(connection.getInputStream(), encoding);
    dispose();
    return result;
  } catch (IOException e) {
    throw new HttpException("Failed URL: " + url, e);
  }
}

相关文章