Search in sources :

Example 86 with FileOutputStream

use of java.io.FileOutputStream in project titan by thinkaurelius.

the class HBaseStatus method write.

public static HBaseStatus write(String path, String hbaseVersion) {
    File f = new File(path);
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(path);
        fos.write(String.format("%s", hbaseVersion).getBytes());
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
    return new HBaseStatus(f, hbaseVersion);
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File)

Example 87 with FileOutputStream

use of java.io.FileOutputStream in project Shuttle by timusus.

the class TaggerUtils method copyFile.

static void copyFile(File sourceFile, File destFile) throws IOException {
    if (!destFile.getParentFile().exists())
        destFile.getParentFile().mkdirs();
    if (!destFile.exists()) {
        destFile.createNewFile();
    }
    FileChannel source = null;
    FileChannel destination = null;
    try {
        source = new FileInputStream(sourceFile).getChannel();
        destination = new FileOutputStream(destFile).getChannel();
        destination.transferFrom(source, 0, source.size());
    } finally {
        if (source != null) {
            source.close();
        }
        if (destination != null) {
            destination.close();
        }
    }
}
Also used : FileChannel(java.nio.channels.FileChannel) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 88 with FileOutputStream

use of java.io.FileOutputStream in project blueprints by tinkerpop.

the class GMLWriterTest method testEncoding.

// Note: this is only a very lightweight test of writer/reader encoding.
// It is known that there are characters which, when written by GMLWriter,
// cause parse errors for GraphMLReader.
// However, this happens uncommonly enough that is not yet known which characters those are.
public void testEncoding() throws Exception {
    Graph g = new TinkerGraph();
    Vertex v = g.addVertex(1);
    v.setProperty("text", "é");
    GMLWriter w = new GMLWriter(g);
    File f = File.createTempFile("test", "txt");
    f.deleteOnExit();
    OutputStream out = new FileOutputStream(f);
    w.outputGraph(out);
    out.close();
    Graph g2 = new TinkerGraph();
    GMLReader r = new GMLReader(g2);
    InputStream in = new FileInputStream(f);
    r.inputGraph(in);
    in.close();
    Vertex v2 = g2.getVertex(1);
    assertEquals("é", v2.getProperty("text"));
}
Also used : Vertex(com.tinkerpop.blueprints.Vertex) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) Graph(com.tinkerpop.blueprints.Graph) TinkerGraph(com.tinkerpop.blueprints.impls.tg.TinkerGraph) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 89 with FileOutputStream

use of java.io.FileOutputStream in project robospice by stephanenicolas.

the class OkHttpBigBinaryRequest method processStream.

@Override
public InputStream processStream(final int contentLength, final InputStream inputStream) throws IOException {
    OutputStream fileOutputStream = null;
    try {
        // touch
        boolean isTouchedNow = cacheFile.setLastModified(System.currentTimeMillis());
        if (!isTouchedNow) {
            Ln.d("Modification time of file %s could not be changed normally ", cacheFile.getAbsolutePath());
        }
        fileOutputStream = new FileOutputStream(cacheFile);
        readBytes(inputStream, new ProgressByteProcessor(this, fileOutputStream, contentLength));
        return new FileInputStream(cacheFile);
    } finally {
        IOUtils.closeQuietly(fileOutputStream);
    }
}
Also used : ProgressByteProcessor(com.octo.android.robospice.request.ProgressByteProcessor) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) FileInputStream(java.io.FileInputStream)

Example 90 with FileOutputStream

use of java.io.FileOutputStream in project robospice by stephanenicolas.

the class InFileInputStreamObjectPersisterTest method testLoadDataFromCache_expired.

public void testLoadDataFromCache_expired() throws Exception {
    File cachedFile = inputStreamCacheManager.getCacheFile(TEST_CACHE_KEY);
    FileOutputStream fileOutputStream = new FileOutputStream(cachedFile);
    IOUtils.write("coucou", fileOutputStream);
    IOUtils.closeQuietly(fileOutputStream);
    cachedFile.setLastModified(System.currentTimeMillis() - FIVE_SECONDS);
    InputStream inputStream = inputStreamCacheManager.loadDataFromCache(TEST_CACHE_KEY, DurationInMillis.ONE_SECOND);
    assertNull(inputStream);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

FileOutputStream (java.io.FileOutputStream)6586 File (java.io.File)3769 IOException (java.io.IOException)2864 FileInputStream (java.io.FileInputStream)1189 OutputStream (java.io.OutputStream)1071 BufferedOutputStream (java.io.BufferedOutputStream)907 InputStream (java.io.InputStream)864 FileNotFoundException (java.io.FileNotFoundException)682 OutputStreamWriter (java.io.OutputStreamWriter)644 Test (org.junit.Test)528 BufferedWriter (java.io.BufferedWriter)313 PrintWriter (java.io.PrintWriter)311 ZipEntry (java.util.zip.ZipEntry)311 BufferedInputStream (java.io.BufferedInputStream)287 DataOutputStream (java.io.DataOutputStream)275 ZipOutputStream (java.util.zip.ZipOutputStream)273 ByteArrayOutputStream (java.io.ByteArrayOutputStream)267 ArrayList (java.util.ArrayList)247 Writer (java.io.Writer)215 URL (java.net.URL)206