Source:
<code>public void paint(final Graphics2D graphics, final GridCoverage2DReader gridCoverageReader, GeneralParameterValue[] readParams, final RasterSymbolizer symbolizer, Interpolation interpolation, final Color background) throws Exception { if (graphics == null) { throw new NullPointerException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "graphics")); } if (gridCoverageReader == null) { throw new NullPointerException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "gridCoverageReader")); } if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(new StringBuilder("Drawing reader ").append(gridCoverageReader.toString()) .toString()); setupInterpolationHints(interpolation); int[] bandIndicesTmp = null; <START> ChannelSelection channelSelection = symbolizer.getChannelSelection(); <END> if (channelSelection!=null){ SelectedChannelType[] channels = channelSelection.getSelectedChannels(); if (channels!=null){ bandIndicesTmp = new int[channels.length]; for (int i=0;i<channels.length;i++){ bandIndicesTmp[i]= Integer.parseInt(channels[i].getChannelName())-1; } } } final int[] bandIndices = bandIndicesTmp; Parameter<int[]> bandIndicesParam = null; if (gridCoverageReader.getFormat().getReadParameters().getDescriptor().descriptors(). contains(AbstractGridFormat.BANDS) && bandIndices != null) { bandIndicesParam = (Parameter<int[]>) AbstractGridFormat.BANDS.createValue(); bandIndicesParam.setValue(bandIndices); List<GeneralParameterValue> paramList = new ArrayList<GeneralParameterValue>(); paramList.addAll(Arrays.asList(readParams)); paramList.add(bandIndicesParam); readParams = paramList.toArray(new GeneralParameterValue[paramList.size()]); } RenderedImage finalImage = renderImage(gridCoverageReader, readParams, symbolizer, interpolation, background); if (finalImage != null) { try { paintImage(graphics, finalImage); } finally { if (finalImage instanceof PlanarImage) { ImageUtilities.disposePlanarImageChain((PlanarImage) finalImage); } } } }</code><technical_language>sense do band selection check for bands param support once? externalize in a single method? copies grabbing indices channel selection, above</technical_language>

Target:
public void paint(final Graphics2D graphics, final GridCoverage2DReader gridCoverageReader, GeneralParameterValue[] readParams, final RasterSymbolizer symbolizer, Interpolation interpolation, final Color background) throws Exception { if (graphics == null) { throw new NullPointerException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "graphics")); } if (gridCoverageReader == null) { throw new NullPointerException(Errors.format(ErrorKeys.NULL_ARGUMENT_$1, "gridCoverageReader")); } if (LOGGER.isLoggable(Level.FINE)) LOGGER.fine(new StringBuilder("Drawing reader ").append(gridCoverageReader.toString()) .toString()); setupInterpolationHints(interpolation); RasterSymbolizer finalSymbolizer = symbolizer; if (isBandsSelectionApplicable(gridCoverageReader, symbolizer)){ applyBandsSelectionParameter(gridCoverageReader, readParams, symbolizer); finalSymbolizer = setupSymbolizerForBandsSelection(symbolizer); } RenderedImage finalImage = renderImage(gridCoverageReader, readParams, finalSymbolizer, interpolation, background); if (finalImage != null) { try { paintImage(graphics, finalImage); } finally { if (finalImage instanceof PlanarImage) { ImageUtilities.disposePlanarImageChain((PlanarImage) finalImage); } } } }