You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by 风云天空 <10...@qq.com> on 2016/03/21 04:08:33 UTC

can I use the source code with some modify for mutil-threading in my company project.

I modify the code below:from:
private void loadICCProfile() throws IOException
{
    InputStream input = null;
    try
    {
        input = this.stream.createInputStream();

        // if the embedded profile is sRGB then we can use Java's built-in profile, which
        // results in a large performance gain as it's our native color space, see PDFBOX-2587
        
        profile = ICC_Profile.getInstance(input);
        if (is_sRGB(profile))
        {
            awtColorSpace = (ICC_ColorSpace)ColorSpace.getInstance(ColorSpace.CS_sRGB);
            iccProfile = awtColorSpace.getProfile();
        }
        else
        {
            awtColorSpace = new ICC_ColorSpace(profile);
            iccProfile = profile;
        }

        // set initial colour
        float[] initial = new float[getNumberOfComponents()];
        for (int c = 0; c < getNumberOfComponents(); c++)
        {
            initial[c] = Math.max(0, getRangeForComponent(c).getMin());
        }
        initialColor = new PDColor(initial, this);

        // create a color in order to trigger a ProfileDataException
        // or CMMException due to invalid profiles, see PDFBOX-1295 and PDFBOX-1740
        new Color(awtColorSpace, new float[getNumberOfComponents()], 1f);
    }
    catch (RuntimeException e)
    {
        if (e instanceof ProfileDataException ||
            e instanceof CMMException ||
            e instanceof IllegalArgumentException)
        {
            // fall back to alternateColorSpace color space
            awtColorSpace = null;
            alternateColorSpace = getAlternateColorSpace();
            LOG.error("Can't read embedded ICC profile (" + e.getLocalizedMessage() + "), using alternate color space: " + alternateColorSpace.getName());
            initialColor = alternateColorSpace.getInitialColor();
        }
        else
        {
            throw e;
        }
    }
    finally
    {
        IOUtils.closeQuietly(input);
    }
}
TO:private void loadICCProfile() throws IOException
{
    InputStream input = null;
    try
    {
        input = this.stream.createInputStream();

        // if the embedded profile is sRGB then we can use Java's built-in profile, which
        // results in a large performance gain as it's our native color space, see PDFBOX-2587
        ICC_Profile profile = null;
        synchronized(ICC_Profile.class){
            profile = ICC_Profile.getInstance(input);
        }
        if (is_sRGB(profile))
        {
            awtColorSpace = (ICC_ColorSpace)ColorSpace.getInstance(ColorSpace.CS_sRGB);
            iccProfile = awtColorSpace.getProfile();
        }
        else
        {
            awtColorSpace = new ICC_ColorSpace(profile);
            iccProfile = profile;
        }

        // set initial colour
        float[] initial = new float[getNumberOfComponents()];
        for (int c = 0; c < getNumberOfComponents(); c++)
        {
            initial[c] = Math.max(0, getRangeForComponent(c).getMin());
        }
        initialColor = new PDColor(initial, this);

        // create a color in order to trigger a ProfileDataException
        // or CMMException due to invalid profiles, see PDFBOX-1295 and PDFBOX-1740
        new Color(awtColorSpace, new float[getNumberOfComponents()], 1f);
    }
    catch (RuntimeException e)
    {
        if (e instanceof ProfileDataException ||
            e instanceof CMMException ||
            e instanceof IllegalArgumentException)
        {
            // fall back to alternateColorSpace color space
            awtColorSpace = null;
            alternateColorSpace = getAlternateColorSpace();
            LOG.error("Can't read embedded ICC profile (" + e.getLocalizedMessage() + "), using alternate color space: " + alternateColorSpace.getName());
            initialColor = alternateColorSpace.getInitialColor();
        }
        else
        {
            throw e;
        }
    }
    finally
    {
        IOUtils.closeQuietly(input);
    }
}
modify content:ICC_Profile profile = null;
synchronized(ICC_Profile.class){
  profile = ICC_Profile.getInstance(input);
}

Re: can I use the source code with some modify for mutil-threading in my company project.

Posted by Tilman Hausherr <TH...@t-online.de>.
Hello 风云天空,

It is an open source software. The license is here:
https://www.apache.org/licenses/LICENSE-2.0

re the problem you had ("NullPointerException in multithreading") - have 
you tried a different JDK, i.e. openJDK?

Please do also read this:
https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=43647087

Tilman

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org