@Override protected Subject getSubjectInstance(final String subjectName) { return new FileSubject(new File(rootDir, subjectName)); }
private List<Integer> getSchemaIds(){ Scanner s = getIdFileScanner(); List<Integer> ids = new ArrayList<Integer>(); try { while (s.hasNextLine()) { if(s.hasNext()) { // only read non-empty lines ids.add(s.nextInt()); } s.nextLine(); } return ids; } finally { s.close(); } }
config = RepositoryUtil.configFromProperties(props); Integer lastId = null; HashSet<String> schemaFileNames = getSchemaFiles(); HashSet<Integer> foundIds = new HashSet<Integer>(); for (Integer id : getSchemaIds()) { if (id > largestId) { largestId = id; "' duplicated in " + idFile.getAbsolutePath()); fileReadable(getSchemaFile(id)); schemaFileNames.remove(getSchemaFileName(id)); readSchemaForId(lastId.toString()));
config = RepositoryUtil.configFromProperties(props); Integer lastId = null; HashSet<String> schemaFileNames = getSchemaFiles(); HashSet<Integer> foundIds = new HashSet<Integer>(); for (Integer id : getSchemaIds()) { if (id > largestId) { largestId = id; "' duplicated in " + idFile.getAbsolutePath()); fileReadable(getSchemaFile(id)); schemaFileNames.remove(getSchemaFileName(id)); readSchemaForId(lastId.toString()));
private synchronized SchemaEntry createNewSchemaFile(String schema) { try { int newId = largestId + 1; File f = getSchemaFile(String.valueOf(newId)); if (!f.exists() && f.createNewFile()) { Writer output = new BufferedWriter(new FileWriter(f)); try { output.write(schema); output.flush(); } finally { output.close(); } latest = new SchemaEntry(String.valueOf(newId), schema); largestId++; return latest; } else { throw new RuntimeException( "Unable to register schema, schema file either exists already " + " or couldn't create new file"); } } catch (NumberFormatException e) { throw new RuntimeException( "Unable to register schema, invalid schema latest schema id ", e); } catch (IOException e) { throw new RuntimeException( "Unable to register schema, couldn't create schema file ", e); } }
private synchronized SchemaEntry createNewSchemaFile(String schema) { try { int newId = largestId + 1; File f = getSchemaFile(String.valueOf(newId)); if (!f.exists() && f.createNewFile()) { Writer output = new BufferedWriter(new FileWriter(f)); try { output.write(schema); output.flush(); } finally { output.close(); } latest = new SchemaEntry(String.valueOf(newId), schema); largestId++; return latest; } else { throw new RuntimeException( "Unable to register schema, schema file either exists already " + " or couldn't create new file"); } } catch (NumberFormatException e) { throw new RuntimeException( "Unable to register schema, invalid schema latest schema id ", e); } catch (IOException e) { throw new RuntimeException( "Unable to register schema, couldn't create schema file ", e); } }
private List<Integer> getSchemaIds(){ Scanner s = getIdFileScanner(); List<Integer> ids = new ArrayList<Integer>(); try { while (s.hasNextLine()) { if(s.hasNext()) { // only read non-empty lines ids.add(s.nextInt()); } s.nextLine(); } return ids; } finally { s.close(); } }
private String getSchemaFileName(int id) { return getSchemaFileName(String.valueOf(id)); }
private File getSchemaFile(String id) { return new File(subjectDir, getSchemaFileName(id)); }
private File getSchemaFile(String id) { return new File(subjectDir, getSchemaFileName(id)); }
private String getSchemaFileName(int id) { return getSchemaFileName(String.valueOf(id)); }
private File getSchemaFile(int id) { return getSchemaFile(String.valueOf(id)); }
private File getSchemaFile(int id) { return getSchemaFile(String.valueOf(id)); }
@Override public synchronized SchemaEntry lookupBySchema(String schema) { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schemaInFile = readSchemaForIdOrNull(idStr); if (schema.equals(schemaInFile)) { return new SchemaEntry(idStr, schema); } } return null; }
@Override protected Subject getSubjectInstance(final String subjectName) { return new FileSubject(new File(rootDir, subjectName)); }
private String readSchemaForId(String id) { File schemaFile = getSchemaFile(id); return readSchemaFile(schemaFile); }
@Override public synchronized SchemaEntry register(String schema) throws SchemaValidationException { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); SchemaEntry entry = lookupBySchema(schema); if (entry == null) { entry = createNewSchemaFile(schema); appendLineToFile(idFile, entry.getId()); latest = entry; } return entry; }
private String readSchemaForId(String id) { File schemaFile = getSchemaFile(id); return readSchemaFile(schemaFile); }
@Override public synchronized SchemaEntry lookupBySchema(String schema) { isValid(); RepositoryUtil.validateSchemaOrSubject(schema); for (Integer id : getSchemaIds()) { String idStr = id.toString(); String schemaInFile = readSchemaForIdOrNull(idStr); if (schema.equals(schemaInFile)) { return new SchemaEntry(idStr, schema); } } return null; }
private String readSchemaFile(File schemaFile) { try { return readAllAsString(schemaFile); } catch (FileNotFoundException e) { throw new RuntimeException( "Could not read schema contents at: " + schemaFile.getAbsolutePath(), e); } }