public static String getStringMaxLength(final String iText, final int iMax) { return getStringMaxLength(iText, iMax, ""); }
public static Object encode(final Object iValue) { if (iValue instanceof String) { return java2unicode(((String) iValue).replace("\\", "\\\\").replace("\"", "\\\"")); } else return iValue; }
public static String readStreamAsString(final InputStream iStream) throws IOException { return readStreamAsString(iStream, StandardCharsets.UTF_8); }
private ODocument loadConfiguration() { try { final File f = getConfigFile(); if (f != null && f.exists()) { final String configurationContent = OIOUtils.readFileAsString(f); return new ODocument().fromJSON(configurationContent); } } catch (Exception e) { throw OException.wrapException(new OConfigurationException( "Cannot load Command Cache Cache configuration file '" + CONFIG_FILE + "'. Command Cache will use default settings"), e); } return null; }
final FileInputStream in = new FileInputStream(folderName); try { OIOUtils.copyStream(in, zos, -1); } finally { in.close(); + "%% elapsed=" + OIOUtils.getTimeAsString(System.currentTimeMillis() - begin) + "");
private void writeFile() { try { final StringBuilder output = new StringBuilder(); output.append("{\"result\":["); int i = 0; for (OWorkload workload : workloads) { if (i++ > 0) output.append(","); output.append(workload.getFinalResultAsJson()); } output.append("]}"); OIOUtils.writeFile(new File(settings.resultOutputFile), output.toString()); } catch (IOException e) { System.err.println("\nError on writing the result file : " + e.getMessage()); } }
protected void dumpProgress() { final long now = System.currentTimeMillis(); final long extractorProgress = extractor.getProgress(); final long extractorTotal = extractor.getTotal(); final long extractorItemsSec = (long) ((extractorProgress - stats.lastExtractorProgress) * 1000f / (now - stats.lastLap)); final String extractorUnit = extractor.getUnit(); final long loaderProgress = loader.getProgress(); final long loaderItemsSec = (long) ((loaderProgress - stats.lastLoaderProgress) * 1000f / (now - stats.lastLap)); final String loaderUnit = loader.getUnit(); final String extractorTotalFormatted = extractorTotal > -1 ? String.format("%,d", extractorTotal) : "?"; if (extractorTotal == -1) { out(LOG_LEVELS.INFO, "+ extracted %,d %s (%,d %s/sec) - %,d %s -> loaded %,d %s (%,d %s/sec) Total time: %s [%d warnings, %d errors]", extractorProgress, extractorUnit, extractorItemsSec, extractorUnit, extractor.getProgress(), extractor.getUnit(), loaderProgress, loaderUnit, loaderItemsSec, loaderUnit, OIOUtils.getTimeAsString(now - startTime), stats.warnings.get(), stats.errors.get()); } else { float extractorPercentage = ((float) extractorProgress * 100 / extractorTotal); out(LOG_LEVELS.INFO, "+ %3.2f%% -> extracted %,d/%,d %s (%,d %s/sec) - %,d %s -> loaded %,d %s (%,d %s/sec) Total time: %s [%d warnings, %d errors]", extractorPercentage, extractorProgress, extractorTotal, extractorUnit, extractorItemsSec, extractorUnit, extractor.getProgress(), extractor.getUnit(), loaderProgress, loaderUnit, loaderItemsSec, loaderUnit, OIOUtils.getTimeAsString(now - startTime), stats.warnings.get(), stats.errors.get()); } stats.lastExtractorProgress = extractorProgress; stats.lastLoaderProgress = loaderProgress; stats.lastLap = now; }
public <RET extends ORecord> RET fromJSON(final InputStream iContentResult) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); OIOUtils.copyStream(iContentResult, out, -1); ORecordSerializerJSON.INSTANCE.fromString(out.toString(), this, null); return (RET) this; }
@Override public boolean equals(final Object o) { if (o == null || !(o instanceof OBuffer)) return false; return OIOUtils.equals(buffer, ((OBuffer) o).buffer); }
public static Object encode(final Object iValue) { return OIOUtils.encode(iValue); }
protected void scanDatabaseDirectory(final File directory, DatabaseFound found) { if (directory.exists() && directory.isDirectory()) { final File[] files = directory.listFiles(); if (files != null) for (File db : files) { if (db.isDirectory()) { final File plocalFile = new File(db.getAbsolutePath() + "/database.ocf"); final String dbPath = db.getPath().replace('\\', '/'); final int lastBS = dbPath.lastIndexOf('/', dbPath.length() - 1) + 1;// -1 of dbPath may be ended with slash if (plocalFile.exists()) { found.found(OIOUtils.getDatabaseNameFromPath(dbPath.substring(lastBS))); } } } } }
if (!arg.startsWith("-")) { try { final String config = OIOUtils.readFileAsString(new File(arg));
private boolean updateCfgOnDisk() throws IOException { File f = getConfigFile(); if (f != null) { OLogManager.instance().debug(this, "Saving Command Cache config for db: %s", databaseName); OIOUtils.writeFile(f, configuration.toJSON("prettyPrint")); return true; } return false; }
protected void dumpProgress() { final long now = System.currentTimeMillis(); final long extractorProgress = extractor.getProgress(); final long extractorTotal = extractor.getTotal(); final long extractorItemsSec = (long) ((extractorProgress - stats.lastExtractorProgress) * 1000f / (now - stats.lastLap)); final String extractorUnit = extractor.getUnit(); final long loaderProgress = loader.getProgress(); final long loaderItemsSec = (long) ((loaderProgress - stats.lastLoaderProgress) * 1000f / (now - stats.lastLap)); final String loaderUnit = loader.getUnit(); final String extractorTotalFormatted = extractorTotal > -1 ? String.format("%,d", extractorTotal) : "?"; if (extractorTotal == -1) { OETLContextWrapper.getInstance().getMessageHandler().info(this, "+ extracted %,d %s (%,d %s/sec) - %,d %s -> loaded %,d %s (%,d %s/sec) Total time: %s [%d warnings, %d errors]", extractorProgress, extractorUnit, extractorItemsSec, extractorUnit, extractor.getProgress(), extractor.getUnit(), loaderProgress, loaderUnit, loaderItemsSec, loaderUnit, OIOUtils.getTimeAsString(now - startTime), stats.warnings.get(), stats.errors.get()); } else { float extractorPercentage = ((float) extractorProgress * 100 / extractorTotal); OETLContextWrapper.getInstance().getMessageHandler().info(this, "+ %3.2f%% -> extracted %,d/%,d %s (%,d %s/sec) - %,d %s -> loaded %,d %s (%,d %s/sec) Total time: %s [%d warnings, %d errors]", extractorPercentage, extractorProgress, extractorTotal, extractorUnit, extractorItemsSec, extractorUnit, extractor.getProgress(), extractor.getUnit(), loaderProgress, loaderUnit, loaderItemsSec, loaderUnit, OIOUtils.getTimeAsString(now - startTime), stats.warnings.get(), stats.errors.get()); } stats.lastExtractorProgress = extractorProgress; stats.lastLoaderProgress = loaderProgress; stats.lastLap = now; }
/** * Creates a new instance by the raw stream usually read from the database. New instances are not persistent until {@link #save()} * is called. * * @param iSource Raw stream as InputStream */ public ODocument(final InputStream iSource) throws IOException { final ByteArrayOutputStream out = new ByteArrayOutputStream(); OIOUtils.copyStream(iSource, out, -1); _source = out.toByteArray(); setup(); }
public static String readFileAsString(final File iFile) throws java.io.IOException { return readStreamAsString(new FileInputStream(iFile)); }
protected static OETLProcessor parseConfigAndParameters(String[] args) { final OCommandContext context = createDefaultContext(); ODocument configuration = new ODocument().fromJSON("{}"); for (final String arg : args) { if (arg.charAt(0) != '-') { try { final String config = OIOUtils.readFileAsString(new File(arg)); configuration.merge(new ODocument().fromJSON(config, "noMap"), true, true); // configuration = ; ODocument cfgGlobal = configuration.field("config"); if (cfgGlobal != null) { for (String f : cfgGlobal.fieldNames()) { context.setVariable(f, cfgGlobal.field(f)); } } } catch (IOException e) { throw new OConfigurationException("Error on loading config file: " + arg, e); } } } // override with args passes by command line for (final String arg : args) { if (arg.charAt(0) == '-') { final String[] parts = arg.substring(1).split("="); context.setVariable(parts[0], parts[1]); } } return new OETLProcessor().parse(configuration, context); }
public static Object encode(final Object iValue) { if (iValue instanceof String) { return java2unicode(((String) iValue).replace("\\", "\\\\").replace("\"", "\\\"")); } else return iValue; }
public static String getStringMaxLength(final String iText, final int iMax) { return getStringMaxLength(iText, iMax, ""); }
private static void extractFile(final ZipInputStream in, final File outdir, final String name, final OCommandOutputListener iListener) throws IOException { if (iListener != null) iListener.onMessage("\n- Uncompressing file " + name + "..."); final BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(new File(outdir, name))); try { OIOUtils.copyStream(in, out, -1); } finally { out.close(); } }