Java InputStream Read getInputStream(Class ownerClass, String subName, String extension)

Here you can find the source of getInputStream(Class ownerClass, String subName, String extension)

Description

Opens an InputStream for a class-associated resource.

License

Open Source License

Parameter

Parameter Description
ownerClass the owner class
subName the resource sub-name, or null to open the resource that is named like the class
extension the file name extension

Return

the input stream

Declaration

public static InputStream getInputStream(Class<?> ownerClass, String subName, String extension) 

Method Source Code

//package com.java2s;
/**//www .j ava 2 s  . com
 * Copyright (c) 2011 Martin Geisse
 *
 * This file is distributed under the terms of the MIT license.
 */

import java.io.InputStream;

public class Main {
    /**
     * Opens an {@link InputStream} for a class-associated resource.
     * @param ownerClass the owner class
     * @param subName the resource sub-name, or null to open the
     * resource that is named like the class
     * @param extension the file name extension
     * @return the input stream
     */
    public static InputStream getInputStream(Class<?> ownerClass, String subName, String extension) {
        String localName;
        if (subName == null) {
            localName = ownerClass.getSimpleName() + '.' + extension;
        } else {
            localName = ownerClass.getSimpleName() + '_' + subName + '.' + extension;
        }
        return ownerClass.getResourceAsStream(localName);
    }
}

Related

  1. getFileContent(InputStream in)
  2. getFileContent(InputStream inputStream)
  3. getFileContent(InputStream is)
  4. getFileContent(InputStream stream)
  5. getInputStream(Class clazz)
  6. getInputstream(File compressedFile)
  7. getInputStream(JarFile file, ZipEntry entry)
  8. getInputStream(Object caller, String name)
  9. getInputStreamAsResource(Class clazz, String fileName)