Search in sources :

Example 71 with FileInputStream

use of java.io.FileInputStream in project hadoop by apache.

the class TestShortCircuitShm method testStartupShutdown.

@Test(timeout = 60000)
public void testStartupShutdown() throws Exception {
    File path = new File(TEST_BASE, "testStartupShutdown");
    path.mkdirs();
    SharedFileDescriptorFactory factory = SharedFileDescriptorFactory.create("shm_", new String[] { path.getAbsolutePath() });
    FileInputStream stream = factory.createDescriptor("testStartupShutdown", 4096);
    ShortCircuitShm shm = new ShortCircuitShm(ShmId.createRandom(), stream);
    shm.free();
    stream.close();
    FileUtil.fullyDelete(path);
}
Also used : File(java.io.File) FileInputStream(java.io.FileInputStream) SharedFileDescriptorFactory(org.apache.hadoop.io.nativeio.SharedFileDescriptorFactory) Test(org.junit.Test)

Example 72 with FileInputStream

use of java.io.FileInputStream in project hadoop by apache.

the class TestEnhancedByteBufferAccess method testIndirectFallbackReads.

/**
   * Test fallback reads on a stream which does not support the
   * ByteBufferReadable * interface.
   */
@Test
public void testIndirectFallbackReads() throws Exception {
    final String testPath = GenericTestUtils.getTestDir("indirectFallbackTestFile").getAbsolutePath();
    final int TEST_FILE_LENGTH = 16385;
    final int RANDOM_SEED = 23453;
    FileOutputStream fos = null;
    FileInputStream fis = null;
    try {
        fos = new FileOutputStream(testPath);
        Random random = new Random(RANDOM_SEED);
        byte[] original = new byte[TEST_FILE_LENGTH];
        random.nextBytes(original);
        fos.write(original);
        fos.close();
        fos = null;
        fis = new FileInputStream(testPath);
        testFallbackImpl(fis, original);
    } finally {
        IOUtils.cleanup(LOG, fos, fis);
        new File(testPath).delete();
    }
}
Also used : Random(java.util.Random) FileOutputStream(java.io.FileOutputStream) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 73 with FileInputStream

use of java.io.FileInputStream in project hadoop by apache.

the class TestCodec method verifyGzipFile.

private void verifyGzipFile(String filename, String msg) throws IOException {
    BufferedReader r = new BufferedReader(new InputStreamReader(new GZIPInputStream(new FileInputStream(filename))));
    try {
        String line = r.readLine();
        assertEquals("Got invalid line back from " + filename, msg, line);
    } finally {
        r.close();
        new File(filename).delete();
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) SequenceFile(org.apache.hadoop.io.SequenceFile) MapFile(org.apache.hadoop.io.MapFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 74 with FileInputStream

use of java.io.FileInputStream in project hadoop by apache.

the class TestDtUtilShell method testFormatProtoFlag.

@Test
public void testFormatProtoFlag() throws Exception {
    args = new String[] { "get", getUrl, "-format", "protobuf", tokenFilenameGet };
    rc = dt.run(args);
    assertEquals("test mocked get with protobuf format flag exit code", 0, rc);
    Credentials creds = new Credentials();
    Credentials spyCreds = Mockito.spy(creds);
    DataInputStream in = new DataInputStream(new FileInputStream(tokenFilenameGet));
    spyCreds.readTokenStorageStream(in);
    Mockito.verify(spyCreds).readProto(in);
}
Also used : DataInputStream(java.io.DataInputStream) Credentials(org.apache.hadoop.security.Credentials) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 75 with FileInputStream

use of java.io.FileInputStream in project hadoop by apache.

the class TestDtUtilShell method testFormatJavaFlag.

@Test
public void testFormatJavaFlag() throws Exception {
    args = new String[] { "get", getUrl, "-format", "java", tokenFilenameGet };
    rc = dt.run(args);
    assertEquals("test mocked get with java format flag exit code", 0, rc);
    Credentials creds = new Credentials();
    Credentials spyCreds = Mockito.spy(creds);
    DataInputStream in = new DataInputStream(new FileInputStream(tokenFilenameGet));
    spyCreds.readTokenStorageStream(in);
    Mockito.verify(spyCreds).readFields(in);
}
Also used : DataInputStream(java.io.DataInputStream) Credentials(org.apache.hadoop.security.Credentials) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

FileInputStream (java.io.FileInputStream)5931 File (java.io.File)2701 IOException (java.io.IOException)2699 InputStream (java.io.InputStream)1514 FileOutputStream (java.io.FileOutputStream)922 FileNotFoundException (java.io.FileNotFoundException)876 BufferedInputStream (java.io.BufferedInputStream)744 InputStreamReader (java.io.InputStreamReader)680 BufferedReader (java.io.BufferedReader)558 Properties (java.util.Properties)552 Test (org.junit.Test)543 ArrayList (java.util.ArrayList)320 DataInputStream (java.io.DataInputStream)288 OutputStream (java.io.OutputStream)273 ByteArrayInputStream (java.io.ByteArrayInputStream)238 ZipEntry (java.util.zip.ZipEntry)221 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)200 HashMap (java.util.HashMap)195 XmlPullParser (org.xmlpull.v1.XmlPullParser)184 ByteArrayOutputStream (java.io.ByteArrayOutputStream)177