use of java.util.zip.GZIPInputStream in project spark by perwendel.
the class GzipClient method getAndDecompress.
public static String getAndDecompress(String url) throws Exception {
InputStream compressed = get(url);
GZIPInputStream gzipInputStream = new GZIPInputStream(compressed);
String decompressed = IOUtils.toString(gzipInputStream);
return decompressed;
}
use of java.util.zip.GZIPInputStream in project orientdb by orientechnologies.
the class OFileSource method begin.
@Override
public void begin() {
try {
final String fileMode = lockFile ? "rw" : "r";
raf = new RandomAccessFile(input, fileMode);
channel = raf.getChannel();
fis = new FileInputStream(input);
if (fileName.endsWith(".gz"))
fileReader = new InputStreamReader(new GZIPInputStream(fis), encoding);
else {
fileReader = new InputStreamReader(new FileInputStream(input), encoding);
byteToParse = input.length();
}
} catch (Exception e) {
end();
}
byteParsed = 0;
if (lockFile)
try {
lock = channel.lock();
} catch (IOException e) {
OLogManager.instance().error(this, "Error on locking file: %s", e, fileName);
}
log(OETLProcessor.LOG_LEVELS.INFO, "Reading from file " + path + " with encoding " + encoding.displayName());
}
use of java.util.zip.GZIPInputStream in project orientdb by orientechnologies.
the class LuceneAutomaticBackupRestoreTest method shouldExportImport.
@Test
public void shouldExportImport() throws IOException, InterruptedException {
List<?> query = databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
Assert.assertEquals(query.size(), 1);
String jsonConfig = OIOUtils.readStreamAsString(getClass().getClassLoader().getResourceAsStream("automatic-backup.json"));
ODocument doc = new ODocument().fromJSON(jsonConfig);
doc.field("enabled", true);
doc.field("targetFileName", "${DBNAME}.json");
doc.field("targetDirectory", BACKUPDIR);
doc.field("mode", "EXPORT");
doc.field("dbInclude", new String[] { "LuceneAutomaticBackupRestoreTest" });
doc.field("firstTime", new SimpleDateFormat("HH:mm:ss").format(new Date(System.currentTimeMillis() + 2000)));
OIOUtils.writeFile(new File(tempFolder.getRoot().getAbsolutePath() + "/config/automatic-backup.json"), doc.toJSON());
final OAutomaticBackup aBackup = new OAutomaticBackup();
final OServerParameterConfiguration[] config = new OServerParameterConfiguration[] {};
aBackup.config(server, config);
final CountDownLatch latch = new CountDownLatch(1);
aBackup.registerListener(new OAutomaticBackup.OAutomaticBackupListener() {
@Override
public void onBackupCompleted(String database) {
latch.countDown();
}
});
latch.await();
aBackup.sendShutdown();
// RESTORE
databaseDocumentTx.drop();
databaseDocumentTx.create();
GZIPInputStream stream = new GZIPInputStream(new FileInputStream(BACKUFILE + ".json.gz"));
new ODatabaseImport(databaseDocumentTx, stream, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
}
}).importDatabase();
databaseDocumentTx.close();
// VERIFY
databaseDocumentTx.open("admin", "admin");
assertThat(databaseDocumentTx.countClass("City")).isEqualTo(1);
OIndex<?> index = databaseDocumentTx.getMetadata().getIndexManager().getIndex("City.name");
assertThat(index).isNotNull();
assertThat(index.getType()).isEqualTo(OClass.INDEX_TYPE.FULLTEXT.name());
assertThat(databaseDocumentTx.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"))).hasSize(1);
}
use of java.util.zip.GZIPInputStream in project orientdb by orientechnologies.
the class LuceneExportImportTest method testExportImport.
@Test
public void testExportImport() {
String file = "./target/exportTest.json";
List<?> query = db.query(new OSQLSynchQuery<Object>("select from City where name lucene 'Rome'"));
assertThat(query).hasSize(1);
try {
//export the DB
new ODatabaseExport(db, file, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
}
}).exportDatabase();
db.drop();
db.create();
GZIPInputStream stream = new GZIPInputStream(new FileInputStream(file + ".gz"));
//import
new ODatabaseImport(db, stream, new OCommandOutputListener() {
@Override
public void onMessage(String s) {
System.out.println(s);
}
}).importDatabase();
} catch (IOException e) {
Assert.fail(e.getMessage());
}
db.commit();
long city = db.countClass("City");
Assert.assertEquals(city, 1);
OIndex<?> index = db.getMetadata().getIndexManager().getIndex("City.name");
Assert.assertNotNull(index);
assertThat(index.getSize()).isEqualTo(1L);
Assert.assertEquals(index.getType(), "FULLTEXT");
Assert.assertEquals(index.getAlgorithm(), "LUCENE");
query = db.query(new OSQLSynchQuery<Object>("select from City "));
assertThat(query.size()).isEqualTo(1);
query = db.query(new OSQLSynchQuery<Object>("select from City where name lucene 'rome'"));
assertThat(query).hasSize(1);
}
use of java.util.zip.GZIPInputStream in project weiciyuan by qii.
the class JavaHttpUtility method readResult.
private String readResult(HttpURLConnection urlConnection) throws WeiboException {
InputStream is = null;
BufferedReader buffer = null;
GlobalContext globalContext = GlobalContext.getInstance();
String errorStr = globalContext.getString(R.string.timeout);
globalContext = null;
try {
is = urlConnection.getInputStream();
String content_encode = urlConnection.getContentEncoding();
if (!TextUtils.isEmpty(content_encode) && content_encode.equals("gzip")) {
is = new GZIPInputStream(is);
}
buffer = new BufferedReader(new InputStreamReader(is));
StringBuilder strBuilder = new StringBuilder();
String line;
while ((line = buffer.readLine()) != null) {
strBuilder.append(line);
}
// AppLogger.d("result=" + strBuilder.toString());
return strBuilder.toString();
} catch (IOException e) {
e.printStackTrace();
throw new WeiboException(errorStr, e);
} finally {
Utility.closeSilently(is);
Utility.closeSilently(buffer);
urlConnection.disconnect();
}
}
Aggregations