use of java.io.Reader in project cogtool by cogtool.
the class ObjectPersister method load.
// registerForPersistence
/**
* Load an Object from a file. This method assumes that all error checking
* and prompting/correction for the validity of the file has already
* been completed.
*
* @param src the File location of the saved Object
* @return a new instantiated Object
* @throws java.io.IOException if any file operation fails or the SAX XML
* parser fails
*/
public Object load(File src) throws IOException {
// See if an object is already loaded for the given file
String canonicalFileName = src.getCanonicalPath();
PersistInfo info = getInfoByName(canonicalFileName);
if (info != null) {
return info.obj;
}
// Attempt to create a file of 3x size in the temp directory
// to hold the expanded XML serialization.
File sizeCheckFile = File.createTempFile(tmpFilePrefix, ".size", tmpDir);
try {
checkDiskSpace(sizeCheckFile, 3 * src.length(), "Not enough temp space on disk to open file: " + src);
} finally {
sizeCheckFile.delete();
}
// If we're here, no exception was thrown; create checkpoint directory
File chkptFile = createTempDirectory();
// Open file as ZipFile and decompress
ZipFile zip = null;
try {
zip = new ZipFile(src);
// Unzip the file to the checkpoint directory
ZipUtil.unzip(zip, chkptFile);
} catch (ZipException ex) {
IOException newE = new IOException("load encountered zip compression error");
newE.initCause(ex);
throw newE;
} finally {
if (zip != null) {
zip.close();
}
}
// Load object from the expanded XML serialization
ObjectLoader l = new ObjectLoader();
Object obj = null;
Reader reader = null;
try {
reader = new InputStreamReader(new FileInputStream(new File(chkptFile, PERSIST_FILE)), "UTF-8");
Collection<?> objSet = l.load(new InputSource(reader), null);
// There should be only one top-level object
Iterator<?> objs = objSet.iterator();
if (objs.hasNext()) {
obj = objs.next();
}
// Register this file for future lookup, both by object
// and by file name
info = new PersistInfo(obj, chkptFile, src);
objInfos.put(obj, info);
fileInfos.put(canonicalFileName, info);
} catch (ParserConfigurationException e) {
IOException newE = new IOException("load encountered parser error");
newE.initCause(e);
throw newE;
} catch (SAXException e) {
IOException newE = new IOException("load encountered SAX error");
newE.initCause(e);
throw newE;
} finally {
if (reader != null) {
reader.close();
}
}
return obj;
}
use of java.io.Reader in project che by eclipse.
the class CheBootstrap method readConfigurationAliases.
private Map<String, Set<String>> readConfigurationAliases() {
URL aliasesResource = getClass().getClassLoader().getResource(PROPERTIES_ALIASES_CONFIG_FILE);
Map<String, Set<String>> aliases = new HashMap<>();
if (aliasesResource != null) {
Properties properties = new Properties();
File aliasesFile = new File(aliasesResource.getFile());
try (Reader reader = Files.newReader(aliasesFile, Charset.forName("UTF-8"))) {
properties.load(reader);
} catch (IOException e) {
throw new IllegalStateException(format("Unable to read configuration aliases from file %s", aliasesFile), e);
}
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
String value = (String) entry.getValue();
aliases.put((String) entry.getKey(), Splitter.on(',').splitToList(value).stream().map(String::trim).collect(toSet()));
}
}
return aliases;
}
use of java.io.Reader in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementAdapterTest method assertSetClob.
@Test
public void assertSetClob() throws SQLException {
Reader reader = new SerializableStringReader();
actual.setClob(1, (Clob) null);
actual.setClob(2, reader);
actual.setClob(3, reader, 100L);
assertParameter(actual, 1, null);
assertParameter(actual, 2, reader);
assertParameter(actual, 3, reader);
}
use of java.io.Reader in project sharding-jdbc by dangdangdotcom.
the class PreparedStatementAdapterTest method assertSetCharacterStream.
@Test
public void assertSetCharacterStream() throws SQLException {
Reader reader = new SerializableStringReader();
actual.setCharacterStream(1, reader);
actual.setCharacterStream(2, reader, 100);
actual.setCharacterStream(3, reader, 100L);
assertParameter(actual, 1, reader);
assertParameter(actual, 2, reader);
assertParameter(actual, 3, reader);
}
use of java.io.Reader in project druid by druid-io.
the class HadoopDruidIndexerConfig method fromDistributedFileSystem.
@SuppressWarnings("unchecked")
public static HadoopDruidIndexerConfig fromDistributedFileSystem(String path) {
try {
Path pt = new Path(path);
FileSystem fs = pt.getFileSystem(new Configuration());
Reader reader = new InputStreamReader(fs.open(pt));
return fromMap((Map<String, Object>) HadoopDruidIndexerConfig.JSON_MAPPER.readValue(reader, new TypeReference<Map<String, Object>>() {
}));
} catch (Exception e) {
throw Throwables.propagate(e);
}
}
Aggregations