use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class ExpenseServlet method init.
@SuppressWarnings({ "resource", "unchecked" })
@Override
public void init() throws ServletException {
CSVSerializer expenseSerializer = new CSVSerializer(Expense.class);
expenseSerializer.setKeys("date", "type", "amount", "description");
// Load the initial expense data
InputStream inputStream = ExpenseServlet.class.getResourceAsStream("expenses.csv");
try {
expenses = (List<Expense>) expenseSerializer.readObject(inputStream);
} catch (IOException exception) {
throw new ServletException(exception);
} catch (SerializationException exception) {
throw new ServletException(exception);
}
// Index the initial expenses
for (Expense expense : expenses) {
int id = nextID++;
expense.setID(id);
expenseMap.put(id, expense);
}
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class ColorSchemeBuilderWindow method reloadContent.
private void reloadContent() {
BXMLSerializer bxmlSerializer = new BXMLSerializer();
try {
Component sampleContent = (Component) bxmlSerializer.readObject(ColorSchemeBuilderWindow.class, "sample_content.bxml");
sampleContentBorder.setContent(sampleContent);
} catch (IOException exception) {
throw new RuntimeException(exception);
} catch (SerializationException exception) {
throw new RuntimeException(exception);
}
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class ColorSchemeBuilderWindow method copyToClipboard.
private void copyToClipboard() {
int numberOfPaletteColors = getNumberOfPaletteColors();
ArrayList<String> colors = new ArrayList<>(numberOfPaletteColors);
for (int i = 0; i < numberOfPaletteColors; i++) {
ColorChooserButton colorChooserButton = colorChooserButtons.get(i);
Color color = colorChooserButton.getSelectedColor();
colors.add(ColorUtilities.toStringValue(color));
}
LocalManifest clipboardContent = new LocalManifest();
try {
clipboardContent.putText(JSONSerializer.toString(colors));
} catch (SerializationException exception) {
Prompt.prompt(exception.getMessage(), this);
}
Clipboard.setContent(clipboardContent);
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class RESTDemoServlet method doPost.
@SuppressWarnings("resource")
@Override
protected URL doPost(Path path, Object value) throws QueryException {
if (path.getLength() > 0 || value == null) {
throw new QueryException(Query.Status.BAD_REQUEST);
}
// Write the value to a temp file
File directory = new File(System.getProperty("java.io.tmpdir"));
File file;
try {
file = File.createTempFile(getClass().getName(), null, directory);
JSONSerializer jsonSerializer = new JSONSerializer();
jsonSerializer.writeObject(value, new FileOutputStream(file));
} catch (IOException exception) {
throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
} catch (SerializationException exception) {
throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
}
// Return the location of the resource
URL location;
try {
location = new URL(getLocation(), file.getName());
} catch (MalformedURLException exception) {
throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
}
return location;
}
use of org.apache.pivot.serialization.SerializationException in project pivot by apache.
the class RESTDemoServlet method doPut.
@SuppressWarnings("resource")
@Override
protected boolean doPut(Path path, Object value) throws QueryException {
if (path.getLength() != 1 || value == null) {
throw new QueryException(Query.Status.BAD_REQUEST);
}
// Write the value to the temp file
File directory = new File(System.getProperty("java.io.tmpdir"));
File file = new File(directory, path.get(0));
if (!file.exists()) {
throw new QueryException(Query.Status.NOT_FOUND);
}
try {
JSONSerializer jsonSerializer = new JSONSerializer();
jsonSerializer.writeObject(value, new FileOutputStream(file));
} catch (IOException exception) {
throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
} catch (SerializationException exception) {
throw new QueryException(Query.Status.INTERNAL_SERVER_ERROR);
}
return false;
}
Aggregations