/** * Ensures that the object is writeable. If not an exception will be thrown. * This is intended to be called within all update methods. */ protected void assertWriteable() { if (readOnly) { throw new OsmosisRuntimeException( "The object has been marked as read-only. It must be cloned to make changes."); } }
/** * This is called by the input thread to validate that no errors have * occurred on the output thread. */ private void checkForOutputErrors() { // Check for reading thread error. if (!outputOkay) { throw new OsmosisRuntimeException("An output error has occurred, aborting."); } }
/** * Commits any outstanding transaction. */ public void commit() { if (connection != null) { try { connection.commit(); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to commit changes.", e); } } }
/** * {@inheritDoc} */ public void writeByte(byte value) { try { output.writeByte(value); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to write byte " + value + " to the store.", e); } }
/** * {@inheritDoc} */ public void writeString(String value) { try { output.writeUTF(value); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to write String (" + value + ") to the store.", e); } } }
/** * Writes a new line in the output file. */ public void endRecord() { try { writer.newLine(); midRecord = false; } catch (IOException e) { throw new OsmosisRuntimeException("Unable to end record.", e); } }
private String getProperty(String propertyName) { String value; value = properties.getProperty(propertyName); if (value == null) { throw new OsmosisRuntimeException("Property " + propertyName + " cannot be found."); } return value; }
private int readChangesetCount(ResultSet countSet) { try (ResultSet resultSet = countSet) { resultSet.next(); return resultSet.getInt("changesetCount"); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to read the changeset count.", e); } }
private Properties loadProperties(File configFile) { properties = new Properties(); try (FileInputStream fileInputStream = new FileInputStream(configFile)) { properties.load(fileInputStream); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to load properties from config file " + configFile); } return properties; }
private static void addEntityTypeMapping(EntityType entityType, String memberType) { if (entityToMemberMap.containsKey(entityType)) { throw new OsmosisRuntimeException("Entity type (" + entityType + ") already has a mapping."); } entityToMemberMap.put(entityType, memberType); memberToEntityMap.put(memberType, entityType); }
private Date readTimeField(ResultSet timeSet) { try (ResultSet rs = timeSet) { Date dbTime; timeSet.next(); dbTime = timeSet.getTimestamp("SystemTime"); return new Date(dbTime.getTime()); } catch (SQLException e) { throw new OsmosisRuntimeException("Unable to read the time from the database server.", e); } }
/** * {@inheritDoc} */ public void storeIdentifierForClass(StoreWriter storeWriter, Class<?> clazz) { byte id; if (classToByteMap.containsKey(clazz)) { id = classToByteMap.get(clazz).byteValue(); } else { throw new OsmosisRuntimeException("The class " + clazz + " is not supported by this store class register."); } storeWriter.writeByte(id); }
/** * Flushes all changes to file. */ public void complete() { try (BufferedWriter writer = new BufferedWriter(new FileWriter(file))) { // Produce a report on the user statistics. writeUserReport(writer); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to write report to file " + file + "."); } }
private Fileformat.Blob parseBlob(byte[] data) { try { return Fileformat.Blob.parseFrom(data); } catch (InvalidProtocolBufferException e) { throw new OsmosisRuntimeException("Unable to parse PBF blob", e); } }
/** * Returns the length of data. * * @return The data length in bytes. */ public long length() { try { return randomFile.length(); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to obtain the length of the storage file.", e); } }
private void runAndValidate() { decodedEntities = new ArrayList<>(); // Parse the blob. PbfBlock pbfBlock = blobToBlockMapper.apply(rawBlob); // We don't expect to see more than one header per file. if (pbfBlock.getHeaderBlock().isPresent()) { throw new OsmosisRuntimeException("Received more than one PBF header block."); } pbfBlock.getPrimitiveBlock().ifPresent(this::processOsmPrimitives); }
private void parseString(String input) { try (InputStream inputStream = new ByteArrayInputStream(input.getBytes("UTF-8"))) { parser.parse(inputStream, new OsmHandler(entityInspector, true)); } catch (UnsupportedEncodingException e) { throw new OsmosisRuntimeException("String encoding exception", e); } catch (IOException e) { throw new OsmosisRuntimeException("IOException", e); } catch (SAXException e) { throw new OsmosisRuntimeException("Parse exception", e); } }
private Date buildDate(String utcString) { SimpleDateFormat dateFormat; dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getTimeZone("UTC")); try { return dateFormat.parse(utcString); } catch (ParseException e) { throw new OsmosisRuntimeException("The date string (" + utcString + ") could not be parsed.", e); } }
@Override public void complete() { try { switchTypes(); processBatch(); flush(); } catch (IOException e) { throw new OsmosisRuntimeException("Unable to complete the PBF file.", e); } }
/** * Performs any validation and pre-processing required for all entity types. */ private void processEntityPrerequisites(Entity entity) { // We can't write an entity with a null timestamp. if (entity.getTimestamp() == null) { throw new OsmosisRuntimeException("Entity(" + entity.getType() + ") " + entity.getId() + " does not have a timestamp set."); } // Process the user data. writeUser(entity.getUser()); }