Java Resource Get getResourceAsStream(Class aClass, String name)

Here you can find the source of getResourceAsStream(Class aClass, String name)

Description

get Resource As Stream

License

Open Source License

Declaration

private static ImageInputStream getResourceAsStream(Class<?> aClass,
            String name) throws IOException 

Method Source Code

//package com.java2s;
/*//w w  w.  ja  v a 2 s.  c  o  m
 * Copyright (C) 2010 Brockmann Consult GmbH (info@brockmann-consult.de)
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 3 of the License, or (at your option)
 * any later version.
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, see http://www.gnu.org/licenses/
 */

import javax.imageio.stream.FileCacheImageInputStream;
import javax.imageio.stream.ImageInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.text.MessageFormat;

public class Main {
    private static ImageInputStream getResourceAsStream(Class<?> aClass,
            String name) throws IOException {
        final InputStream is = aClass.getResourceAsStream(name);

        if (is == null) {
            throw new IOException(MessageFormat.format(
                    "resource {0} not found", name));
        }
        return new FileCacheImageInputStream(is, null);
    }
}

Related

  1. getResourceAsFile(Class clazz, String name)
  2. getResourceAsFile(Class clazz, String rscName)
  3. getResourceAsFile(final Class clazz, final String name)
  4. getResourceAsFile(final String filename, final Class theClass)
  5. getResourceAsFile(String name)
  6. getResourceAsStream(final Class caller, final String resource)
  7. getResourceAsStream(String resourceLocation)
  8. getResourceAsString(String prefix, String resource)
  9. getResourceAsString(String resource)