/** {@inheritDoc} */ @Override public String toString() { try { return ToJson.toJsonString(mDesc); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
/** {@inheritDoc} */ @Override public String toString() { try { return ToJson.toJsonString(mDesc); } catch (IOException ioe) { throw new RuntimeException(ioe); } }
/** * Encodes an Avro record into JSON. * * @param record Avro record to encode. * @return Pretty JSON representation of the record. * @throws IOException on error. */ public static String toJsonString(IndexedRecord record) throws IOException { final Schema schema = record.getSchema(); return toJsonString(record, schema); }
/** * Implements the --do=dump operation. * * @throws Exception on error. */ private void dumpLayout() throws Exception { final FijiTableLayout layout = mFiji.getMetaTable().getTableLayout(mTableURI.getTable()); final StringBuilder json = new StringBuilder(); json.append("/*\n"); json.append(" The raw JSON view of table layouts is intended for use by\n"); json.append(" system administrators or for debugging purposes.\n"); json.append("\n"); json.append(" Most users should use the 'fiji-schema-shell' DDL tool to modify\n"); json.append(" your table layouts instead.\n"); json.append("*/\n"); json.append(ToJson.toJsonString(layout.getDesc())); if (mWriteTo.isEmpty()) { System.out.println(json.toString()); } else { final String fileName = String.format("%s.json", mWriteTo); final FileOutputStream fos = new FileOutputStream(fileName); try { fos.write(Bytes.toBytes(json.toString())); } finally { ResourceUtils.closeOrLog(fos); } } }
/** * Dumps the history of layouts of a given table. * * @throws Exception on error. */ private void history() throws Exception { // Gather all of the layouts stored in the metaTable. final NavigableMap<Long, FijiTableLayout> timedLayouts = mFiji.getMetaTable().getTimedTableLayoutVersions(mTableURI.getTable(), mMaxVersions); if (timedLayouts.isEmpty()) { throw new RuntimeException("No such table: " + mTableURI.getTable()); } for (Map.Entry<Long, FijiTableLayout> entry: timedLayouts.entrySet()) { final long timestamp = entry.getKey(); final FijiTableLayout layout = entry.getValue(); final String json = ToJson.toJsonString(layout.getDesc()); if (mWriteTo.isEmpty()) { // SCHEMA-14: Add a newline to separate the dumped JSON versions of the layout. System.out.printf("timestamp: %d:%n%s%n", timestamp, json); } else { final String fileName = String.format("%s-%d.json", mWriteTo, timestamp); final FileOutputStream fos = new FileOutputStream(fileName); try { fos.write(Bytes.toBytes(json)); } finally { ResourceUtils.closeOrLog(fos); } } } }