Search in sources :

Example 56 with GZIPInputStream

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;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) InputStream(java.io.InputStream)

Example 57 with GZIPInputStream

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());
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream)

Example 58 with GZIPInputStream

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);
}
Also used : OAutomaticBackup(com.orientechnologies.orient.server.handler.OAutomaticBackup) CountDownLatch(java.util.concurrent.CountDownLatch) Date(java.util.Date) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OServerParameterConfiguration(com.orientechnologies.orient.server.config.OServerParameterConfiguration) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 59 with GZIPInputStream

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);
}
Also used : OSQLSynchQuery(com.orientechnologies.orient.core.sql.query.OSQLSynchQuery) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ODatabaseImport(com.orientechnologies.orient.core.db.tool.ODatabaseImport) OCommandOutputListener(com.orientechnologies.orient.core.command.OCommandOutputListener) ODatabaseExport(com.orientechnologies.orient.core.db.tool.ODatabaseExport) Test(org.junit.Test)

Example 60 with GZIPInputStream

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();
    }
}
Also used : GlobalContext(org.qii.weiciyuan.support.utils.GlobalContext) GZIPInputStream(java.util.zip.GZIPInputStream) WeiboException(org.qii.weiciyuan.support.error.WeiboException) InputStreamReader(java.io.InputStreamReader) GZIPInputStream(java.util.zip.GZIPInputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) BufferedReader(java.io.BufferedReader) InterruptedIOException(java.io.InterruptedIOException) IOException(java.io.IOException)

Aggregations

GZIPInputStream (java.util.zip.GZIPInputStream)376 InputStream (java.io.InputStream)144 IOException (java.io.IOException)125 ByteArrayInputStream (java.io.ByteArrayInputStream)120 FileInputStream (java.io.FileInputStream)98 ByteArrayOutputStream (java.io.ByteArrayOutputStream)77 InputStreamReader (java.io.InputStreamReader)57 File (java.io.File)56 BufferedReader (java.io.BufferedReader)45 BufferedInputStream (java.io.BufferedInputStream)41 Test (org.junit.Test)41 FileOutputStream (java.io.FileOutputStream)30 URL (java.net.URL)25 InflaterInputStream (java.util.zip.InflaterInputStream)25 OutputStream (java.io.OutputStream)24 GZIPOutputStream (java.util.zip.GZIPOutputStream)21 ObjectInputStream (java.io.ObjectInputStream)19 HttpURLConnection (java.net.HttpURLConnection)19 URLConnection (java.net.URLConnection)17 HashMap (java.util.HashMap)15