org.xipki.util.IoUtil.save()方法的使用及代码示例

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

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

IoUtil.save介绍

暂无

代码示例

代码示例来源:origin: org.xipki/security

private void createExampleRepository(File dir, int numSlots) throws IOException {
 for (int i = 0; i < numSlots; i++) {
  File slotDir = new File(dir, i + "-" + (800000 + i));
  slotDir.mkdirs();
  File slotInfoFile = new File(slotDir, "slot.info");
  IoUtil.save(slotInfoFile, "namedCurveSupported=true\n".getBytes());
 }
}

代码示例来源:origin: xipki/xipki

public static void save(String fileName, byte[] encoded) throws IOException {
 save(new File(expandFilepath(fileName)), encoded);
}

代码示例来源:origin: org.xipki/ca-dbtool

public DigestDiffReporter(String reportDirname, byte[] caCertBytes) throws IOException {
 this.reportDirname = ParamUtil.requireNonBlank("reportDirname", reportDirname);
 File dir = new File(reportDirname);
 dir.mkdirs();
 IoUtil.save(new File(dir, "ca.der"), caCertBytes);
 this.missingWriter = new BufferedWriter(new FileWriter(new File(dir, "missing")));
 this.unexpectedWriter = new BufferedWriter(new FileWriter(new File(dir, "unexpected")));
 this.diffWriter = new BufferedWriter(new FileWriter(new File(dir, "diff")));
 this.goodWriter = new BufferedWriter(new FileWriter(new File(dir, "good")));
 this.errorWriter = new BufferedWriter(new FileWriter(new File(dir, "error")));
 start();
}

代码示例来源:origin: org.xipki/util

public static void save(String fileName, byte[] encoded) throws IOException {
 save(new File(expandFilepath(fileName)), encoded);
}

代码示例来源:origin: org.xipki/ca-mgmt-client

public DigestDiffReporter(String reportDirname, byte[] caCertBytes) throws IOException {
 this.reportDirname = Args.notBlank(reportDirname, "reportDirname");
 File dir = new File(reportDirname);
 dir.mkdirs();
 IoUtil.save(new File(dir, "ca.der"), caCertBytes);
 String dirPath = dir.getPath();
 this.missingWriter = Files.newBufferedWriter(Paths.get(dirPath, "missing"));
 this.unexpectedWriter = Files.newBufferedWriter(Paths.get(dirPath, "unexpected"));
 this.diffWriter = Files.newBufferedWriter(Paths.get(dirPath, "diff"));
 this.goodWriter = Files.newBufferedWriter(Paths.get(dirPath, "good"));
 this.errorWriter = Files.newBufferedWriter(Paths.get(dirPath, "error"));
 start();
}

代码示例来源:origin: org.xipki.shell/shell-base

private void replaceFile(File file, String oldText, String newText) throws Exception {
 BufferedReader reader = Files.newBufferedReader(file.toPath());
 ByteArrayOutputStream writer = new ByteArrayOutputStream();
 boolean changed = false;
 try {
  String line;
  while ((line = reader.readLine()) != null) {
   if (line.contains(oldText)) {
    changed = true;
    writer.write(line.replace(oldText, newText).getBytes());
   } else {
    writer.write(line.getBytes());
   }
   writer.write('\n');
  }
 } finally {
  writer.close();
  reader.close();
 }
 if (changed) {
  File newFile = new File(file.getPath() + "-new");
  byte[] newBytes = writer.toByteArray();
  IoUtil.save(file, newBytes);
  newFile.renameTo(file);
 }
}

代码示例来源:origin: org.xipki.shells/shell-base

private void replaceFile(File file, String oldText, String newText) throws Exception {
 BufferedReader reader = new BufferedReader(new FileReader(file));
 ByteArrayOutputStream writer = new ByteArrayOutputStream();
 boolean changed = false;
 try {
  String line;
  while ((line = reader.readLine()) != null) {
   if (line.contains(oldText)) {
    changed = true;
    writer.write(line.replace(oldText, newText).getBytes());
   } else {
    writer.write(line.getBytes());
   }
   writer.write('\n');
  }
 } finally {
  writer.close();
  reader.close();
 }
 if (changed) {
  File newFile = new File(file.getPath() + "-new");
  byte[] newBytes = writer.toByteArray();
  IoUtil.save(file, newBytes);
  newFile.renameTo(file);
 }
}

代码示例来源:origin: org.xipki/ca-server

public CaManagerImpl() {
 this.datasourceFactory = new DataSourceFactory();
 String calockId = null;
 File caLockFile = new File("calock");
 if (caLockFile.exists()) {
  try {
   calockId = new String(IoUtil.read(caLockFile));
  } catch (IOException ex) {
   LOG.error("could not read {}: {}", caLockFile.getName(), ex.getMessage());
  }
 }
 if (calockId == null) {
  calockId = UUID.randomUUID().toString();
  try {
   IoUtil.save(caLockFile, calockId.getBytes());
  } catch (IOException ex) {
   LOG.error("could not save {}: {}", caLockFile.getName(), ex.getMessage());
  }
 }
 String hostAddress = null;
 try {
  hostAddress = IoUtil.getHostAddress();
 } catch (SocketException ex) {
  LOG.warn("could not get host address: {}", ex.getMessage());
 }
 this.lockInstanceId = (hostAddress == null) ? calockId : hostAddress + "/" + calockId;
 this.restResponder = new RestResponder(this);
} // constructor

代码示例来源:origin: org.xipki/ca-dbtool

protected FileOrValueType buildFileOrValue(String content, String fileName) throws IOException {
 if (content == null) {
  return null;
 }
 ParamUtil.requireNonNull("fileName", fileName);
 FileOrValueType ret = new FileOrValueType();
 if (content.length() < 256) {
  ret.setValue(content);
  return ret;
 }
 File file = new File(baseDir, fileName);
 File parent = file.getParentFile();
 if (parent != null && !parent.exists()) {
  parent.mkdirs();
 }
 IoUtil.save(file, content.getBytes("UTF-8"));
 ret.setFile(fileName);
 return ret;
}

代码示例来源:origin: org.xipki/ca-dbtool

protected FileOrBinaryType buildFileOrBinary(byte[] content, String fileName) throws IOException {
 if (content == null) {
  return null;
 }
 ParamUtil.requireNonNull("fileName", fileName);
 FileOrBinaryType ret = new FileOrBinaryType();
 if (content.length < 256) {
  ret.setBinary(content);
  return ret;
 }
 File file = new File(baseDir, fileName);
 File parent = file.getParentFile();
 if (parent != null && !parent.exists()) {
  parent.mkdirs();
 }
 IoUtil.save(file, content);
 ret.setFile(fileName);
 return ret;
}

代码示例来源:origin: org.xipki/ca-mgmt-client

protected FileOrValue buildFileOrValue(String content, String fileName) throws IOException {
 if (content == null) {
  return null;
 }
 Args.notNull(fileName, "fileName");
 FileOrValue ret = new FileOrValue();
 if (content.length() < 256) {
  ret.setValue(content);
  return ret;
 }
 File file = new File(baseDir, fileName);
 IoUtil.mkdirsParent(file.toPath());
 IoUtil.save(file, content.getBytes("UTF-8"));
 ret.setFile(fileName);
 return ret;
}

代码示例来源:origin: org.xipki/ca-mgmt-client

private void exportIssuer(OcspCertstore certstore) throws DataAccessException, IOException {
 System.out.println("exporting table ISSUER");
 List<OcspCertstore.Issuer> issuers = new LinkedList<>();
 certstore.setIssuers(issuers);
 final String sql = "SELECT ID,CERT,REV_INFO FROM ISSUER";
 Statement stmt = null;
 ResultSet rs = null;
 try {
  stmt = createStatement();
  rs = stmt.executeQuery(sql);
  while (rs.next()) {
   int id = rs.getInt("ID");
   OcspCertstore.Issuer issuer = new OcspCertstore.Issuer();
   issuer.setId(id);
   String certFileName = "issuer-conf/cert-issuer-" + id;
   IoUtil.save(new File(baseDir, certFileName), rs.getString("CERT").getBytes("UTF-8"));
   issuer.setCertFile(certFileName);
   issuer.setRevInfo(rs.getString("REV_INFO"));
   issuers.add(issuer);
  }
 } catch (SQLException ex) {
  throw translate(sql, ex);
 } finally {
  releaseResources(stmt, rs);
 }
 System.out.println(" exported table ISSUER");
} // method exportIssuer

代码示例来源:origin: org.xipki/ca-mgmt-client

protected FileOrBinary buildFileOrBinary(byte[] content, String fileName) throws IOException {
 if (content == null) {
  return null;
 }
 Args.notNull(fileName, "fileName");
 FileOrBinary ret = new FileOrBinary();
 if (content.length < 256) {
  ret.setBinary(content);
  return ret;
 }
 File file = new File(baseDir, fileName);
 IoUtil.mkdirsParent(file.toPath());
 IoUtil.save(file, content);
 ret.setFile(fileName);
 return ret;
}

代码示例来源:origin: org.xipki/ca-mgmt-client

@Override
public void close() {
 closeWriter(missingWriter);
 closeWriter(unexpectedWriter);
 closeWriter(diffWriter);
 closeWriter(goodWriter);
 closeWriter(errorWriter);
 int sum = numGood.get() + numDiff.get() + numMissing.get() + numUnexpected.get()
      + numError.get();
 Date now = new Date();
 int durationSec = (int) ((now.getTime() - startTime.getTime()) / 1000);
 String speedStr = (durationSec > 0)
   ? StringUtil.formatAccount(sum / durationSec, false) + " /s" : "--";
 String str = StringUtil.concatObjectsCap(200,
   "      sum : ", StringUtil.formatAccount(sum, false),
   "\n      good: ", StringUtil.formatAccount(numGood.get(), false),
   "\n      diff: ", StringUtil.formatAccount(numDiff.get(), false),
   "\n   missing: ", StringUtil.formatAccount(numMissing.get(), false),
   "\nunexpected: ", StringUtil.formatAccount(numUnexpected.get(), false),
   "\n     error: ", StringUtil.formatAccount(numError.get(), false),
   "\n  duration: ", StringUtil.formatTime(durationSec, false),
   "\nstart time: ", startTime,
   "\n  end time: ", now,
   "\n     speed: ", speedStr, "\n");
 try {
  IoUtil.save(reportDirname + File.separator + "overview.txt", str.getBytes());
 } catch (IOException ex) {
  System.out.println("Could not write overview.txt with following content\n" + str);
 }
} // method close

代码示例来源:origin: org.xipki/security

private void savePkcs11Entry(File dir, byte[] id, String label, byte[] value)
  throws P11TokenException {
 Args.notNull(dir, "dir");
 Args.notNull(id, "id");
 Args.notBlank(label, "label");
 Args.notNull(value, "value");
 assertValidId(id);
 String hexId = hex(id);
 String str = StringUtil.concat(PROP_ID, "=", hexId, "\n", PROP_LABEL, "=", label, "\n",
   PROP_SHA1SUM, "=", HashAlgo.SHA1.hexHash(value), "\n");
 try {
  IoUtil.save(new File(dir, hexId + INFO_FILE_SUFFIX), str.getBytes());
  IoUtil.save(new File(dir, hexId + VALUE_FILE_SUFFIX), value);
 } catch (IOException ex) {
  throw new P11TokenException("could not save certificate");
 }
}

代码示例来源:origin: org.xipki/ca-dbtool

private void exportIssuer(CertstoreType certstore) throws DataAccessException, IOException {
 System.out.println("exporting table ISSUER");
 Issuers issuers = new Issuers();
 certstore.setIssuers(issuers);
 final String sql = "SELECT ID,CERT,REV_INFO FROM ISSUER";
 Statement stmt = null;
 ResultSet rs = null;
 try {
  stmt = createStatement();
  rs = stmt.executeQuery(sql);
  String issuerCertsDir = "issuer-conf";
  new File(issuerCertsDir).mkdirs();
  while (rs.next()) {
   int id = rs.getInt("ID");
   IssuerType issuer = new IssuerType();
   issuer.setId(id);
   String certFileName = issuerCertsDir + "/cert-issuer-" + id;
   IoUtil.save(new File(baseDir, certFileName), rs.getString("CERT").getBytes("UTF-8"));
   issuer.setCertFile(certFileName);
   issuer.setRevInfo(rs.getString("REV_INFO"));
   issuers.getIssuer().add(issuer);
  }
 } catch (SQLException ex) {
  throw translate(sql, ex);
 } finally {
  releaseResources(stmt, rs);
 }
 System.out.println(" exported table ISSUER");
} // method exportIssuer

代码示例来源:origin: org.xipki/ca-dbtool

public void close() {
 closeWriter(missingWriter);
 closeWriter(unexpectedWriter);
 closeWriter(diffWriter);
 closeWriter(goodWriter);
 closeWriter(errorWriter);
 int sum = numGood.get() + numDiff.get() + numMissing.get() + numUnexpected.get()
      + numError.get();
 Date now = new Date();
 int durationSec = (int) ((now.getTime() - startTime.getTime()) / 1000);
 String speedStr = (durationSec > 0)
   ? StringUtil.formatAccount(sum / durationSec, false) + " /s" : "--";
 String str = StringUtil.concatObjectsCap(200,
   "      sum : ", StringUtil.formatAccount(sum, false),
   "\n      good: ", StringUtil.formatAccount(numGood.get(), false),
   "\n      diff: ", StringUtil.formatAccount(numDiff.get(), false),
   "\n   missing: ", StringUtil.formatAccount(numMissing.get(), false),
   "\nunexpected: ", StringUtil.formatAccount(numUnexpected.get(), false),
   "\n     error: ", StringUtil.formatAccount(numError.get(), false),
   "\n  duration: ", StringUtil.formatTime(durationSec, false),
   "\nstart time: ", startTime,
   "\n  end time: ", now,
   "\n     speed: ", speedStr, "\n");
 try {
  IoUtil.save(reportDirname + File.separator + "overview.txt", str.getBytes());
 } catch (IOException ex) {
  System.out.println("Could not write overview.txt with following content\n" + str);
 }
} // method close

代码示例来源:origin: org.xipki/security

IoUtil.save(new File(pubKeyDir, hexId + INFO_FILE_SUFFIX), sb.toString().getBytes());
} catch (IOException ex) {
 throw new P11TokenException(ex.getMessage(), ex);

代码示例来源:origin: org.xipki.shells/ocsp-client-shell

byte[] bytes = reqResp.getRequest();
if (bytes != null) {
 IoUtil.save(reqout, bytes);
byte[] bytes = reqResp.getResponse();
if (bytes != null) {
 IoUtil.save(respout, bytes);

代码示例来源:origin: org.xipki.shell/ocsp-client-shell

byte[] bytes = reqResp.getRequest();
if (bytes != null) {
 IoUtil.save(reqout, bytes);
byte[] bytes = reqResp.getResponse();
if (bytes != null) {
 IoUtil.save(respout, bytes);

相关文章