Program: 47044
Project: 47044
Buggy source:
/** 
 * Construct a proper HTTP response to a received request. After the response has been created, it is sent and the resulting   {@link ChannelFuture} object is returned.See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">RFC-2616</a> for HTTP header field definitions.
 * @param ctx
 * @param output The {@link HttpResponse} object that will be used to construct the response.
 * @param event The {@link MessageEvent} object used to communicate with the client that sentthe request.
 * @param close Set to true to close the channel after sending the response. By default thechannel is not closed after sending.
 * @param startStopListenerDelegate The {@link StartStopListenerDelegate} object that is usedto notify plugins that the  {@link DLNAResource} is about to start playing.
 * @return The {@link ChannelFuture} object via which the response was sent.
 * @throws IOException
 */
public ChannelFuture answer(HttpResponse output,MessageEvent event,final boolean close,final StartStopListenerDelegate startStopListenerDelegate) throws IOException {
  ChannelFuture future=null;
  long CLoverride=-2;
  StringBuilder response=new StringBuilder();
  DLNAResource dlna=null;
  boolean xbox360=mediaRenderer.isXbox360();
  if (argument.startsWith("String_Node_Str")) {
    LOGGER.trace("String_Node_Str" + argument);
    argument=argument.substring(1);
  }
  if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && argument.startsWith("String_Node_Str")) {
    output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
    response.append(HTMLConsole.servePage(argument.substring(8)));
  }
 else   if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && argument.startsWith("String_Node_Str")) {
    String id=argument.substring(argument.indexOf("String_Node_Str") + 4);
    id=id.replace("String_Node_Str","String_Node_Str");
    dlna=PMS.get().getRootFolder(mediaRenderer).getDLNAResource(id,mediaRenderer);
    String fileName=id.substring(id.indexOf('/') + 1);
    if (transferMode != null) {
      output.headers().set("String_Node_Str",transferMode);
    }
    if (dlna != null && dlna.isFolder() && !fileName.startsWith("String_Node_Str")) {
      dlna=null;
    }
    if (dlna != null) {
      if (fileName.startsWith("String_Node_Str")) {
        DLNAImageProfile imageProfile=ImagesUtil.parseThumbRequest(fileName);
        output.headers().set(HttpHeaders.Names.CONTENT_TYPE,imageProfile.getMimeType());
        output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
        output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
        output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
        DLNAThumbnailInputStream thumbInputStream;
        if (!configuration.isShowCodeThumbs() && !dlna.isCodeValid(dlna)) {
          thumbInputStream=dlna.getGenericThumbnailInputStream(null);
        }
 else {
          if (mediaRenderer.isUseMediaInfo()) {
            dlna.checkThumbnail();
          }
          thumbInputStream=dlna.fetchThumbnailInputStream();
        }
        if (dlna instanceof RealFile && FullyPlayed.isFullyPlayedThumbnail(((RealFile)dlna).getFile())) {
          thumbInputStream=FullyPlayed.addFullyPlayedOverlay(thumbInputStream);
        }
        inputStream=thumbInputStream.transcode(imageProfile,mediaRenderer != null ? mediaRenderer.isThumbnailPadding() : false);
      }
 else       if (dlna.getMedia() != null && dlna.getMedia().getMediaType() == MediaType.IMAGE && dlna.isCodeValid(dlna)) {
        DLNAImageProfile imageProfile=ImagesUtil.parseImageRequest(fileName,null);
        if (imageProfile == null) {
          if (dlna.getMedia().getImageInfo() != null && dlna.getMedia().getImageInfo().getFormat() != null) {
switch (dlna.getMedia().getImageInfo().getFormat()) {
case GIF:
              imageProfile=DLNAImageProfile.GIF_LRG;
            break;
case PNG:
          imageProfile=DLNAImageProfile.PNG_LRG;
        break;
default :
      imageProfile=DLNAImageProfile.JPEG_LRG;
  }
}
 else {
  imageProfile=DLNAImageProfile.JPEG_LRG;
}
}
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,imageProfile.getMimeType());
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
try {
InputStream imageInputStream;
if (dlna.getPlayer() instanceof ImagePlayer) {
  ProcessWrapper transcodeProcess=dlna.getPlayer().launchTranscode(dlna,dlna.getMedia(),new OutputParams(configuration));
  imageInputStream=transcodeProcess != null ? transcodeProcess.getInputStream(0) : null;
}
 else {
  imageInputStream=dlna.getInputStream();
}
if (imageInputStream == null) {
  LOGGER.warn("String_Node_Str",fileName);
}
 else {
  inputStream=DLNAImageInputStream.toImageInputStream(imageInputStream,imageProfile,false);
}
}
 catch (IOException ie) {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str");
output.setStatus(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
future=event.getChannel().write(output);
if (close) {
  future.addListener(ChannelFutureListener.CLOSE);
}
LOGGER.debug("String_Node_Str",dlna.getName(),ie.getMessage() != null ? ie.getMessage() : ie.getClass().getSimpleName());
LOGGER.trace("String_Node_Str",ie);
return future;
}
}
 else if (dlna.getMedia() != null && fileName.contains("String_Node_Str") && dlna.isCodeValid(dlna)) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
DLNAMediaSubtitle sub=dlna.getMediaSubtitle();
if (sub != null) {
if (sub.isExternal()) {
  try {
    if (sub.getType() == SubtitleType.SUBRIP && mediaRenderer.isRemoveTagsFromSRTsubs()) {
      inputStream=SubtitleUtils.removeSubRipTags(sub.getExternalFile());
    }
 else {
      inputStream=new FileInputStream(sub.getExternalFile());
    }
    LOGGER.trace("String_Node_Str",sub);
  }
 catch (  IOException ioe) {
    LOGGER.debug("String_Node_Str",sub,ioe.getMessage());
    LOGGER.trace("String_Node_Str",ioe);
  }
}
 else {
  LOGGER.trace("String_Node_Str",sub);
}
}
 else {
LOGGER.trace("String_Node_Str");
}
}
 else if (dlna.isCodeValid(dlna)) {
DLNAResource.Rendering origRendering=null;
if (!mediaRenderer.equals(dlna.getDefaultRenderer())) {
origRendering=dlna.updateRendering(mediaRenderer);
}
Range.Time splitRange=dlna.getSplitRange();
if (range.getStart() == null && splitRange.getStart() != null) {
range.setStart(splitRange.getStart());
}
if (range.getEnd() == null && splitRange.getEnd() != null) {
range.setEnd(splitRange.getEnd());
}
long totalsize=dlna.length(mediaRenderer);
boolean ignoreTranscodeByteRangeRequests=mediaRenderer.ignoreTranscodeByteRangeRequests();
if (!ignoreTranscodeByteRangeRequests || totalsize != DLNAMediaInfo.TRANS_SIZE || (ignoreTranscodeByteRangeRequests && lowRange == 0 && totalsize == DLNAMediaInfo.TRANS_SIZE)) {
inputStream=dlna.getInputStream(Range.create(lowRange,highRange,range.getStart(),range.getEnd()),mediaRenderer);
if (dlna.isResume()) {
  range.setStart(dlna.getResume().getTimeOffset() / (double)1000);
}
}
Format format=dlna.getFormat();
if (format != null && format.isVideo()) {
if (dlna.getMedia() != null && !configuration.isDisableSubtitles() && dlna.getMediaSubtitle() != null && dlna.getMediaSubtitle().isStreamable()) {
  String subtitleHttpHeader=mediaRenderer.getSubtitleHttpHeader();
  if (isNotBlank(subtitleHttpHeader)) {
    DLNAMediaSubtitle sub=dlna.getMediaSubtitle();
    String subtitleUrl;
    String subExtension=sub.getType().getExtension();
    if (isNotBlank(subExtension)) {
      subExtension="String_Node_Str" + subExtension;
    }
    subtitleUrl="String_Node_Str" + PMS.get().getServer().getHost() + ':'+ PMS.get().getServer().getPort()+ "String_Node_Str"+ id.substring(0,id.indexOf('/'))+ "String_Node_Str"+ subExtension;
    output.headers().set(subtitleHttpHeader,subtitleUrl);
  }
 else {
    LOGGER.trace("String_Node_Str",subtitleHttpHeader == null ? "String_Node_Str" : "String_Node_Str" + subtitleHttpHeader + "String_Node_Str");
  }
}
 else if (LOGGER.isTraceEnabled()) {
  ArrayList<String> reasons=new ArrayList<>();
  if (dlna.getMedia() == null) {
    reasons.add("String_Node_Str");
  }
  if (configuration.isDisableSubtitles()) {
    reasons.add("String_Node_Str");
  }
  if (dlna.getMediaSubtitle() == null) {
    reasons.add("String_Node_Str");
  }
 else   if (!dlna.getMediaSubtitle().isStreamable()) {
    reasons.add("String_Node_Str");
  }
  LOGGER.trace("String_Node_Str",StringUtil.createReadableCombinedString(reasons));
}
}
String name=dlna.getDisplayName(mediaRenderer);
if (dlna.isNoName()) {
name=dlna.getName() + "String_Node_Str" + dlna.getDisplayName(mediaRenderer);
}
if (inputStream == null) {
if (!ignoreTranscodeByteRangeRequests) {
  LOGGER.error("String_Node_Str" + name);
}
}
 else {
startStopListenerDelegate.start(dlna);
String rendererMimeType=getRendererMimeType(dlna.mimeType(),mediaRenderer,dlna.getMedia());
if (rendererMimeType != null && !"String_Node_Str".equals(rendererMimeType)) {
  output.headers().set(HttpHeaders.Names.CONTENT_TYPE,rendererMimeType);
}
boolean chunked=mediaRenderer.isChunkedTransfer();
if (chunked && totalsize == DLNAMediaInfo.TRANS_SIZE) {
  totalsize=-1;
}
long remaining=totalsize - lowRange;
long requested=highRange - lowRange;
if (requested != 0) {
  long bytes=remaining > -1 ? remaining : inputStream.available();
  if (requested > 0 && bytes > requested) {
    bytes=requested + 1;
  }
  highRange=lowRange + bytes - (bytes > 0 ? 1 : 0);
  LOGGER.trace((chunked ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str" + bytes+ "String_Node_Str");
  output.headers().set(HttpHeaders.Names.CONTENT_RANGE,"String_Node_Str" + lowRange + "String_Node_Str"+ (highRange > -1 ? highRange : "String_Node_Str")+ "String_Node_Str"+ (totalsize > -1 ? totalsize : "String_Node_Str"));
  if (chunked && requested < 0 && totalsize < 0) {
    CLoverride=-1;
  }
 else {
    CLoverride=bytes;
  }
}
 else {
  CLoverride=remaining;
}
highRange=lowRange + CLoverride - (CLoverride > 0 ? 1 : 0);
if (contentFeatures != null) {
  output.headers().set("String_Node_Str",dlna.getDlnaContentFeatures(mediaRenderer));
}
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
}
if (origRendering != null) {
dlna.updateRendering(origRendering);
}
}
}
}
 else if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && (argument.toLowerCase().endsWith("String_Node_Str") || argument.toLowerCase().endsWith("String_Node_Str") || argument.toLowerCase().endsWith("String_Node_Str"))) {
if (argument.toLowerCase().endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
}
 else {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
}
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
inputStream=getResourceInputStream(argument);
}
 else if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && (argument.equals("String_Node_Str") || argument.endsWith("String_Node_Str"))) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CACHE_CONTROL,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
inputStream=getResourceInputStream((argument.equals("String_Node_Str") ? "String_Node_Str" : argument));
if (argument.equals("String_Node_Str")) {
byte b[]=new byte[inputStream.available()];
inputStream.read(b);
String s=new String(b,StandardCharsets.UTF_8);
s=s.replace("String_Node_Str",PMS.get().usn());
if (PMS.get().getServer().getHost() != null) {
s=s.replace("String_Node_Str",PMS.get().getServer().getHost());
s=s.replace("String_Node_Str","String_Node_Str" + PMS.get().getServer().getPort());
}
if (xbox360) {
LOGGER.debug("String_Node_Str");
s=s.replace("String_Node_Str",configuration.getServerDisplayName() + "String_Node_Str");
s=s.replace("String_Node_Str","String_Node_Str");
s=s.replace("String_Node_Str","String_Node_Str" + CRLF + "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF);
}
 else {
s=s.replace("String_Node_Str",configuration.getServerDisplayName());
}
response.append(s);
inputStream=null;
}
}
 else if (method.equals("String_Node_Str") && (argument.contains("String_Node_Str") || argument.contains("String_Node_Str"))) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XBOX_360_2);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XBOX_360_1);
response.append(CRLF);
}
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.PROTOCOLINFO_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.GETSYSTEMUPDATEID_HEADER);
response.append(CRLF);
response.append("String_Node_Str").append(DLNAResource.getSystemUpdateId()).append("String_Node_Str");
response.append(CRLF);
response.append(HTTPXMLHelper.GETSYSTEMUPDATEID_FOOTER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SAMSUNG_ERROR_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SORTCAPS_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SEARCHCAPS_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && (soapaction.contains("String_Node_Str") || soapaction.contains("String_Node_Str"))) {
objectID=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
String containerID=null;
if ((objectID == null || objectID.length() == 0)) {
containerID=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (containerID == null || (xbox360 && !containerID.contains("String_Node_Str"))) {
objectID="String_Node_Str";
}
 else {
objectID=containerID;
containerID=null;
}
}
String sI=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
String rC=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
browseFlag=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (sI != null) {
startingIndex=Integer.parseInt(sI);
}
if (rC != null) {
requestCount=Integer.parseInt(rC);
}
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
if (soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_HEADER);
}
 else {
response.append(HTTPXMLHelper.BROWSERESPONSE_HEADER);
}
response.append(CRLF);
response.append(HTTPXMLHelper.RESULT_HEADER);
response.append(HTTPXMLHelper.DIDL_HEADER);
boolean browseDirectChildren=browseFlag != null && browseFlag.equals("String_Node_Str");
if (soapaction.contains("String_Node_Str")) {
browseDirectChildren=true;
}
String searchCriteria=null;
if (xbox360 && configuration.getUseCache() && PMS.get().getLibrary() != null && containerID != null) {
if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getAlbumFolder() != null) {
objectID=PMS.get().getLibrary().getAlbumFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getArtistFolder() != null) {
objectID=PMS.get().getLibrary().getArtistFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getGenreFolder() != null) {
objectID=PMS.get().getLibrary().getGenreFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getPlaylistFolder() != null) {
objectID=PMS.get().getLibrary().getPlaylistFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getAllFolder() != null) {
objectID=PMS.get().getLibrary().getAllFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str")) {
String artist=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (artist != null) {
  objectID=PMS.get().getLibrary().getArtistFolder().getResourceId();
  searchCriteria=artist;
}
}
}
 else if (soapaction.contains("String_Node_Str")) {
searchCriteria=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
}
List<DLNAResource> files=PMS.get().getRootFolder(mediaRenderer).getDLNAResources(objectID,browseDirectChildren,startingIndex,requestCount,mediaRenderer,searchCriteria);
if (searchCriteria != null && files != null) {
UMSUtils.postSearch(files,searchCriteria);
if (xbox360) {
if (files.size() > 0) {
  files=files.get(0).getChildren();
}
}
}
int minus=0;
if (files != null) {
for (DLNAResource uf : files) {
if (xbox360 && containerID != null) {
  uf.setFakeParentId(containerID);
}
if (uf.isCompatible(mediaRenderer) && (uf.getPlayer() == null || uf.getPlayer().isPlayerCompatible(mediaRenderer))) {
  response.append(uf.getDidlString(mediaRenderer));
}
 else {
  minus++;
}
}
}
response.append(HTTPXMLHelper.DIDL_FOOTER);
response.append(HTTPXMLHelper.RESULT_FOOTER);
response.append(CRLF);
int filessize=0;
if (files != null) {
filessize=files.size();
}
response.append("String_Node_Str").append(filessize - minus).append("String_Node_Str");
response.append(CRLF);
DLNAResource parentFolder=null;
if (files != null && filessize > 0) {
parentFolder=files.get(0).getParent();
}
if (browseDirectChildren && mediaRenderer.isUseMediaInfo() && mediaRenderer.isDLNATreeHack()) {
int totalCount=startingIndex + requestCount + 1;
if (filessize - minus <= 0) {
totalCount=startingIndex;
}
response.append("String_Node_Str").append(totalCount).append("String_Node_Str");
}
 else if (browseDirectChildren) {
response.append("String_Node_Str").append(((parentFolder != null) ? parentFolder.childrenNumber() : filessize) - minus).append("String_Node_Str");
}
 else {
response.append("String_Node_Str");
}
response.append(CRLF);
response.append("String_Node_Str");
if (parentFolder != null) {
response.append(parentFolder.getUpdateId());
}
 else {
response.append('1');
}
response.append("String_Node_Str");
response.append(CRLF);
if (soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_FOOTER);
}
 else {
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
}
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
}
 else if (method.equals("String_Node_Str")) {
output.headers().set("String_Node_Str",PMS.get().usn());
output.headers().set("String_Node_Str","String_Node_Str");
if (soapaction != null) {
String cb=soapaction.replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
try {
URL soapActionUrl=new URL(cb);
String addr=soapActionUrl.getHost();
int port=soapActionUrl.getPort();
try (Socket sock=new Socket(addr,port);OutputStream out=sock.getOutputStream()){
out.write(("String_Node_Str" + argument + "String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + PMS.get().usn()).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + 0).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + addr + "String_Node_Str"+ port).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.flush();
}
 }
 catch (MalformedURLException ex) {
LOGGER.debug("String_Node_Str" + soapaction + "String_Node_Str",ex);
}
}
 else {
LOGGER.debug("String_Node_Str");
}
if (argument.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.eventHeader("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.EVENT_FOOTER);
}
 else if (argument.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.eventHeader("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str","String_Node_Str" + DLNAResource.getSystemUpdateId()));
response.append(HTTPXMLHelper.EVENT_FOOTER);
}
}
 else if (method.equals("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set("String_Node_Str","String_Node_Str");
output.headers().set("String_Node_Str","String_Node_Str");
output.headers().set("String_Node_Str",PMS.get().usn());
output.headers().set("String_Node_Str","String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str").append(DLNAResource.getSystemUpdateId()).append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
}
output.headers().set("String_Node_Str",PMS.get().getServerName());
if (response.length() > 0) {
byte responseData[]=response.toString().getBytes("String_Node_Str");
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + responseData.length);
if (!method.equals("String_Node_Str")) {
ChannelBuffer buf=ChannelBuffers.copiedBuffer(responseData);
output.setContent(buf);
}
future=event.getChannel().write(output);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
 else if (inputStream != null) {
if (CLoverride > -2) {
if (CLoverride > -1 && CLoverride != DLNAMediaInfo.TRANS_SIZE) {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + CLoverride);
}
}
 else {
int contentLength=inputStream.available();
LOGGER.trace("String_Node_Str",contentLength);
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + contentLength);
}
if (range.isStartOffsetAvailable() && dlna != null) {
String timeseekValue=StringUtil.convertTimeToString(range.getStartOrZero(),StringUtil.DURATION_TIME_FORMAT);
String timetotalValue=dlna.getMedia().getDurationString();
String timeEndValue=range.isEndLimitAvailable() ? StringUtil.convertTimeToString(range.getEnd(),StringUtil.DURATION_TIME_FORMAT) : timetotalValue;
output.headers().set("String_Node_Str","String_Node_Str" + timeseekValue + "String_Node_Str"+ timeEndValue+ "String_Node_Str"+ timetotalValue);
output.headers().set("String_Node_Str","String_Node_Str" + timeseekValue + "String_Node_Str"+ timeEndValue+ "String_Node_Str"+ timetotalValue);
}
future=event.getChannel().write(output);
if (lowRange != DLNAMediaInfo.ENDFILE_POS && !method.equals("String_Node_Str")) {
ChannelFuture chunkWriteFuture=event.getChannel().write(new ChunkedStream(inputStream,BUFFER_SIZE));
chunkWriteFuture.addListener(new ChannelFutureListener(){
@Override public void operationComplete(ChannelFuture future){
try {
  inputStream.close();
}
 catch (IOException e) {
  LOGGER.error("String_Node_Str",e);
}
future.getChannel().close();
startStopListenerDelegate.stop();
}
}
);
}
 else {
try {
inputStream.close();
}
 catch (IOException ioe) {
LOGGER.error("String_Node_Str",ioe);
}
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
startStopListenerDelegate.stop();
}
}
 else {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str");
output.setStatus(HttpResponseStatus.NO_CONTENT);
future=event.getChannel().write(output);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
if (LOGGER.isTraceEnabled()) {
StringBuilder header=new StringBuilder();
for (Entry<String,String> entry : output.headers().entries()) {
if (isNotBlank(entry.getKey())) {
header.append("String_Node_Str").append(entry.getKey()).append("String_Node_Str").append(entry.getValue()).append("String_Node_Str");
}
}
String rendererName;
if (mediaRenderer != null) {
if (isNotBlank(mediaRenderer.getRendererName())) {
if (isBlank(mediaRenderer.getConfName()) || mediaRenderer.getRendererName().equals(mediaRenderer.getConfName())) {
rendererName=mediaRenderer.getRendererName();
}
 else {
rendererName=mediaRenderer.getRendererName() + "String_Node_Str" + mediaRenderer.getConfName()+ "String_Node_Str";
}
}
 else if (isNotBlank(mediaRenderer.getConfName())) {
rendererName=mediaRenderer.getConfName();
}
 else {
rendererName="String_Node_Str";
}
}
 else {
rendererName="String_Node_Str";
}
if (method.equals("String_Node_Str")) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header);
}
 else {
String formattedResponse=null;
if (isNotBlank(response)) {
try {
formattedResponse=StringUtil.prettifyXML(response.toString(),4);
}
 catch (SAXException|ParserConfigurationException|XPathExpressionException|TransformerException e) {
formattedResponse="String_Node_Str" + e.getMessage() + "String_Node_Str";
formattedResponse+="String_Node_Str" + response.toString().replaceAll("String_Node_Str","String_Node_Str");
}
}
if (isNotBlank(formattedResponse)) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header,formattedResponse);
Matcher matcher=DIDL_PATTERN.matcher(response);
if (matcher.find()) {
try {
  LOGGER.trace("String_Node_Str",rendererName,StringUtil.prettifyXML(StringEscapeUtils.unescapeXml(matcher.group(1)),2));
}
 catch (SAXException|ParserConfigurationException|XPathExpressionException|TransformerException e) {
  LOGGER.warn("String_Node_Str",e.getMessage());
  LOGGER.trace("String_Node_Str",e);
}
}
}
 else if (inputStream != null && !"String_Node_Str".equals(output.headers().get(HttpHeaders.Names.CONTENT_LENGTH))) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),output.isChunked() ? "String_Node_Str" : "String_Node_Str",header);
}
 else {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header);
}
}
}
return future;
}

Fixed version (ground truth):
/** 
 * Construct a proper HTTP response to a received request. After the response has been created, it is sent and the resulting   {@link ChannelFuture} object is returned.See <a href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">RFC-2616</a> for HTTP header field definitions.
 * @param ctx
 * @param output The {@link HttpResponse} object that will be used to construct the response.
 * @param event The {@link MessageEvent} object used to communicate with the client that sentthe request.
 * @param close Set to true to close the channel after sending the response. By default thechannel is not closed after sending.
 * @param startStopListenerDelegate The {@link StartStopListenerDelegate} object that is usedto notify plugins that the  {@link DLNAResource} is about to start playing.
 * @return The {@link ChannelFuture} object via which the response was sent.
 * @throws IOException
 */
public ChannelFuture answer(HttpResponse output,MessageEvent event,final boolean close,final StartStopListenerDelegate startStopListenerDelegate) throws IOException {
  ChannelFuture future=null;
  long CLoverride=-2;
  StringBuilder response=new StringBuilder();
  DLNAResource dlna=null;
  boolean xbox360=mediaRenderer.isXbox360();
  if (argument.startsWith("String_Node_Str")) {
    LOGGER.trace("String_Node_Str" + argument);
    argument=argument.substring(1);
  }
  if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && argument.startsWith("String_Node_Str")) {
    output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
    response.append(HTMLConsole.servePage(argument.substring(8)));
  }
 else   if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && argument.startsWith("String_Node_Str")) {
    String id=argument.substring(argument.indexOf("String_Node_Str") + 4);
    id=id.replace("String_Node_Str","String_Node_Str");
    dlna=PMS.get().getRootFolder(mediaRenderer).getDLNAResource(id,mediaRenderer);
    String fileName=id.substring(id.indexOf('/') + 1);
    if (transferMode != null) {
      output.headers().set("String_Node_Str",transferMode);
    }
    if (dlna != null && dlna.isFolder() && !fileName.startsWith("String_Node_Str")) {
      dlna=null;
    }
    if (dlna != null) {
      if (fileName.startsWith("String_Node_Str")) {
        DLNAImageProfile imageProfile=ImagesUtil.parseThumbRequest(fileName);
        output.headers().set(HttpHeaders.Names.CONTENT_TYPE,imageProfile.getMimeType());
        output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
        output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
        output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
        DLNAThumbnailInputStream thumbInputStream;
        if (!configuration.isShowCodeThumbs() && !dlna.isCodeValid(dlna)) {
          thumbInputStream=dlna.getGenericThumbnailInputStream(null);
        }
 else {
          if (mediaRenderer.isUseMediaInfo()) {
            dlna.checkThumbnail();
          }
          thumbInputStream=dlna.fetchThumbnailInputStream();
        }
        if (dlna instanceof RealFile && FullyPlayed.isFullyPlayedThumbnail(((RealFile)dlna).getFile())) {
          thumbInputStream=FullyPlayed.addFullyPlayedOverlay(thumbInputStream);
        }
        inputStream=thumbInputStream.transcode(imageProfile,mediaRenderer != null ? mediaRenderer.isThumbnailPadding() : false);
      }
 else       if (dlna.getMedia() != null && dlna.getMedia().getMediaType() == MediaType.IMAGE && dlna.isCodeValid(dlna)) {
        DLNAImageProfile imageProfile=ImagesUtil.parseImageRequest(fileName,null);
        if (imageProfile == null) {
          if (dlna.getMedia().getImageInfo() != null && dlna.getMedia().getImageInfo().getFormat() != null) {
switch (dlna.getMedia().getImageInfo().getFormat()) {
case GIF:
              imageProfile=DLNAImageProfile.GIF_LRG;
            break;
case PNG:
          imageProfile=DLNAImageProfile.PNG_LRG;
        break;
default :
      imageProfile=DLNAImageProfile.JPEG_LRG;
  }
}
 else {
  imageProfile=DLNAImageProfile.JPEG_LRG;
}
}
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,imageProfile.getMimeType());
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
try {
InputStream imageInputStream;
if (dlna.getPlayer() instanceof ImagePlayer) {
  ProcessWrapper transcodeProcess=dlna.getPlayer().launchTranscode(dlna,dlna.getMedia(),new OutputParams(configuration));
  imageInputStream=transcodeProcess != null ? transcodeProcess.getInputStream(0) : null;
}
 else {
  imageInputStream=dlna.getInputStream();
}
if (imageInputStream == null) {
  LOGGER.warn("String_Node_Str",fileName);
}
 else {
  inputStream=DLNAImageInputStream.toImageInputStream(imageInputStream,imageProfile,false);
}
}
 catch (IOException ie) {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str");
output.setStatus(HttpResponseStatus.UNSUPPORTED_MEDIA_TYPE);
future=event.getChannel().write(output);
if (close) {
  future.addListener(ChannelFutureListener.CLOSE);
}
LOGGER.debug("String_Node_Str",dlna.getName(),ie.getMessage() != null ? ie.getMessage() : ie.getClass().getSimpleName());
LOGGER.trace("String_Node_Str",ie);
return future;
}
}
 else if (dlna.getMedia() != null && fileName.contains("String_Node_Str") && dlna.isCodeValid(dlna)) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
DLNAMediaSubtitle sub=dlna.getMediaSubtitle();
if (sub != null) {
if (sub.isExternal()) {
  try {
    if (sub.getType() == SubtitleType.SUBRIP && mediaRenderer.isRemoveTagsFromSRTsubs()) {
      inputStream=SubtitleUtils.removeSubRipTags(sub.getExternalFile());
    }
 else {
      inputStream=new FileInputStream(sub.getExternalFile());
    }
    LOGGER.trace("String_Node_Str",sub);
  }
 catch (  IOException ioe) {
    LOGGER.debug("String_Node_Str",sub,ioe.getMessage());
    LOGGER.trace("String_Node_Str",ioe);
  }
}
 else {
  LOGGER.trace("String_Node_Str",sub);
}
}
 else {
LOGGER.trace("String_Node_Str");
}
}
 else if (dlna.isCodeValid(dlna)) {
DLNAResource.Rendering origRendering=null;
if (!mediaRenderer.equals(dlna.getDefaultRenderer())) {
origRendering=dlna.updateRendering(mediaRenderer);
}
Range.Time splitRange=dlna.getSplitRange();
if (range.getStart() == null && splitRange.getStart() != null) {
range.setStart(splitRange.getStart());
}
if (range.getEnd() == null && splitRange.getEnd() != null) {
range.setEnd(splitRange.getEnd());
}
long totalsize=dlna.length(mediaRenderer);
boolean ignoreTranscodeByteRangeRequests=mediaRenderer.ignoreTranscodeByteRangeRequests();
if (!ignoreTranscodeByteRangeRequests || totalsize != DLNAMediaInfo.TRANS_SIZE || (ignoreTranscodeByteRangeRequests && lowRange == 0 && totalsize == DLNAMediaInfo.TRANS_SIZE)) {
inputStream=dlna.getInputStream(Range.create(lowRange,highRange,range.getStart(),range.getEnd()),mediaRenderer);
if (dlna.isResume()) {
  range.setStart(dlna.getResume().getTimeOffset() / (double)1000);
}
}
Format format=dlna.getFormat();
if (format != null && format.isVideo()) {
if (dlna.getMedia() != null && !configuration.isDisableSubtitles() && dlna.getMediaSubtitle() != null && dlna.getMediaSubtitle().isStreamable()) {
  String subtitleHttpHeader=mediaRenderer.getSubtitleHttpHeader();
  if (isNotBlank(subtitleHttpHeader)) {
    DLNAMediaSubtitle sub=dlna.getMediaSubtitle();
    String subtitleUrl;
    String subExtension=sub.getType().getExtension();
    if (isNotBlank(subExtension)) {
      subExtension="String_Node_Str" + subExtension;
    }
    subtitleUrl="String_Node_Str" + PMS.get().getServer().getHost() + ':'+ PMS.get().getServer().getPort()+ "String_Node_Str"+ id.substring(0,id.indexOf('/'))+ "String_Node_Str"+ subExtension;
    output.headers().set(subtitleHttpHeader,subtitleUrl);
  }
 else {
    LOGGER.trace("String_Node_Str",subtitleHttpHeader == null ? "String_Node_Str" : "String_Node_Str" + subtitleHttpHeader + "String_Node_Str");
  }
}
 else if (LOGGER.isTraceEnabled()) {
  ArrayList<String> reasons=new ArrayList<>();
  if (dlna.getMedia() == null) {
    reasons.add("String_Node_Str");
  }
  if (configuration.isDisableSubtitles()) {
    reasons.add("String_Node_Str");
  }
  if (dlna.getMediaSubtitle() == null) {
    reasons.add("String_Node_Str");
  }
 else   if (!dlna.getMediaSubtitle().isStreamable()) {
    reasons.add("String_Node_Str");
  }
  LOGGER.trace("String_Node_Str",StringUtil.createReadableCombinedString(reasons));
}
}
String name=dlna.getDisplayName(mediaRenderer);
if (dlna.isNoName()) {
name=dlna.getName() + "String_Node_Str" + dlna.getDisplayName(mediaRenderer);
}
if (inputStream == null) {
if (!ignoreTranscodeByteRangeRequests) {
  LOGGER.error("String_Node_Str" + name);
}
}
 else {
startStopListenerDelegate.start(dlna);
String rendererMimeType=getRendererMimeType(dlna.mimeType(),mediaRenderer,dlna.getMedia());
if (rendererMimeType != null && !"String_Node_Str".equals(rendererMimeType)) {
  output.headers().set(HttpHeaders.Names.CONTENT_TYPE,rendererMimeType);
}
boolean chunked=mediaRenderer.isChunkedTransfer();
if (chunked && totalsize == DLNAMediaInfo.TRANS_SIZE) {
  totalsize=-1;
}
long remaining=totalsize - lowRange;
long requested=highRange - lowRange;
if (requested != 0) {
  long bytes=remaining > -1 ? remaining : inputStream.available();
  if (requested > 0 && bytes > requested) {
    bytes=requested + 1;
  }
  highRange=lowRange + bytes - (bytes > 0 ? 1 : 0);
  LOGGER.trace((chunked ? "String_Node_Str" : "String_Node_Str") + "String_Node_Str" + bytes+ "String_Node_Str");
  output.headers().set(HttpHeaders.Names.CONTENT_RANGE,"String_Node_Str" + lowRange + "String_Node_Str"+ (highRange > -1 ? highRange : "String_Node_Str")+ "String_Node_Str"+ (totalsize > -1 ? totalsize : "String_Node_Str"));
  if (chunked && requested < 0 && totalsize < 0) {
    CLoverride=-1;
  }
 else {
    CLoverride=bytes;
  }
}
 else {
  CLoverride=remaining;
}
highRange=lowRange + CLoverride - (CLoverride > 0 ? 1 : 0);
if (contentFeatures != null) {
  output.headers().set("String_Node_Str",dlna.getDlnaContentFeatures(mediaRenderer));
}
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
}
if (origRendering != null) {
dlna.updateRendering(origRendering);
}
}
}
}
 else if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && (argument.toLowerCase().endsWith("String_Node_Str") || argument.toLowerCase().endsWith("String_Node_Str") || argument.toLowerCase().endsWith("String_Node_Str"))) {
if (argument.toLowerCase().endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
}
 else {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
}
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,getFUTUREDATE() + "String_Node_Str");
inputStream=getResourceInputStream(argument);
}
 else if ((method.equals("String_Node_Str") || method.equals("String_Node_Str")) && (argument.equals("String_Node_Str") || argument.endsWith("String_Node_Str"))) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CACHE_CONTROL,"String_Node_Str");
output.headers().set(HttpHeaders.Names.EXPIRES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.ACCEPT_RANGES,"String_Node_Str");
output.headers().set(HttpHeaders.Names.CONNECTION,"String_Node_Str");
inputStream=getResourceInputStream((argument.equals("String_Node_Str") ? "String_Node_Str" : argument));
if (argument.equals("String_Node_Str")) {
byte b[]=new byte[inputStream.available()];
inputStream.read(b);
String s=new String(b,StandardCharsets.UTF_8);
s=s.replace("String_Node_Str",PMS.get().usn());
if (PMS.get().getServer().getHost() != null) {
s=s.replace("String_Node_Str",PMS.get().getServer().getHost());
s=s.replace("String_Node_Str","String_Node_Str" + PMS.get().getServer().getPort());
}
if (xbox360) {
LOGGER.debug("String_Node_Str");
s=s.replace("String_Node_Str",configuration.getServerDisplayName() + "String_Node_Str");
s=s.replace("String_Node_Str","String_Node_Str");
s=s.replace("String_Node_Str","String_Node_Str" + CRLF + "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF+ "String_Node_Str"+ CRLF);
}
 else {
s=s.replace("String_Node_Str",configuration.getServerDisplayName());
}
response.append(s);
inputStream=null;
}
}
 else if (method.equals("String_Node_Str") && (argument.contains("String_Node_Str") || argument.contains("String_Node_Str"))) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XBOX_360_2);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XBOX_360_1);
response.append(CRLF);
}
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.PROTOCOLINFO_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.GETSYSTEMUPDATEID_HEADER);
response.append(CRLF);
response.append("String_Node_Str").append(DLNAResource.getSystemUpdateId()).append("String_Node_Str");
response.append(CRLF);
response.append(HTTPXMLHelper.GETSYSTEMUPDATEID_FOOTER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SAMSUNG_ERROR_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SORTCAPS_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SEARCHCAPS_RESPONSE);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (soapaction != null && (soapaction.contains("String_Node_Str") || soapaction.contains("String_Node_Str"))) {
objectID=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
String containerID=null;
if ((objectID == null || objectID.length() == 0)) {
containerID=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (containerID == null || (xbox360 && !containerID.contains("String_Node_Str"))) {
objectID="String_Node_Str";
}
 else {
objectID=containerID;
containerID=null;
}
}
String sI=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
String rC=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
browseFlag=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (sI != null) {
startingIndex=Integer.parseInt(sI);
}
if (rC != null) {
requestCount=Integer.parseInt(rC);
}
response.append(HTTPXMLHelper.XML_HEADER);
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_HEADER);
response.append(CRLF);
if (soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_HEADER);
}
 else {
response.append(HTTPXMLHelper.BROWSERESPONSE_HEADER);
}
response.append(CRLF);
response.append(HTTPXMLHelper.RESULT_HEADER);
response.append(HTTPXMLHelper.DIDL_HEADER);
boolean browseDirectChildren=browseFlag != null && browseFlag.equals("String_Node_Str");
if (soapaction.contains("String_Node_Str")) {
browseDirectChildren=true;
}
String searchCriteria=null;
if (xbox360 && configuration.getUseCache() && PMS.get().getLibrary() != null && containerID != null) {
if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getAlbumFolder() != null) {
objectID=PMS.get().getLibrary().getAlbumFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getArtistFolder() != null) {
objectID=PMS.get().getLibrary().getArtistFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getGenreFolder() != null) {
objectID=PMS.get().getLibrary().getGenreFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getPlaylistFolder() != null) {
objectID=PMS.get().getLibrary().getPlaylistFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str") && PMS.get().getLibrary().getAllFolder() != null) {
objectID=PMS.get().getLibrary().getAllFolder().getResourceId();
}
 else if (containerID.equals("String_Node_Str")) {
String artist=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
if (artist != null) {
  objectID=PMS.get().getLibrary().getArtistFolder().getResourceId();
  searchCriteria=artist;
}
}
}
 else if (soapaction.contains("String_Node_Str")) {
searchCriteria=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
}
List<DLNAResource> files=PMS.get().getRootFolder(mediaRenderer).getDLNAResources(objectID,browseDirectChildren,startingIndex,requestCount,mediaRenderer,searchCriteria);
if (searchCriteria != null && files != null) {
UMSUtils.postSearch(files,searchCriteria);
if (xbox360) {
if (files.size() > 0) {
  files=files.get(0).getChildren();
}
}
}
int minus=0;
if (files != null) {
for (DLNAResource uf : files) {
if (xbox360 && containerID != null) {
  uf.setFakeParentId(containerID);
}
if (uf.isCompatible(mediaRenderer) && (uf.getPlayer() == null || uf.getPlayer().isPlayerCompatible(mediaRenderer))) {
  response.append(uf.getDidlString(mediaRenderer));
}
 else if (!(files.get(0).getParent() instanceof FileTranscodeVirtualFolder)) {
  minus++;
}
}
}
response.append(HTTPXMLHelper.DIDL_FOOTER);
response.append(HTTPXMLHelper.RESULT_FOOTER);
response.append(CRLF);
int filessize=0;
if (files != null) {
filessize=files.size();
}
response.append("String_Node_Str").append(filessize - minus).append("String_Node_Str");
response.append(CRLF);
DLNAResource parentFolder=null;
if (files != null && filessize > 0) {
parentFolder=files.get(0).getParent();
}
if (browseDirectChildren && mediaRenderer.isUseMediaInfo() && mediaRenderer.isDLNATreeHack()) {
int totalCount=startingIndex + requestCount + 1;
if (filessize - minus <= 0) {
totalCount=startingIndex;
}
response.append("String_Node_Str").append(totalCount).append("String_Node_Str");
}
 else if (browseDirectChildren) {
response.append("String_Node_Str").append(((parentFolder != null) ? parentFolder.childrenNumber() : filessize) - minus).append("String_Node_Str");
}
 else {
response.append("String_Node_Str");
}
response.append(CRLF);
response.append("String_Node_Str");
if (parentFolder != null) {
response.append(parentFolder.getUpdateId());
}
 else {
response.append('1');
}
response.append("String_Node_Str");
response.append(CRLF);
if (soapaction.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.SEARCHRESPONSE_FOOTER);
}
 else {
response.append(HTTPXMLHelper.BROWSERESPONSE_FOOTER);
}
response.append(CRLF);
response.append(HTTPXMLHelper.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
}
 else if (method.equals("String_Node_Str")) {
output.headers().set("String_Node_Str",PMS.get().usn());
output.headers().set("String_Node_Str","String_Node_Str");
if (soapaction != null) {
String cb=soapaction.replace("String_Node_Str","String_Node_Str").replace("String_Node_Str","String_Node_Str");
try {
URL soapActionUrl=new URL(cb);
String addr=soapActionUrl.getHost();
int port=soapActionUrl.getPort();
try (Socket sock=new Socket(addr,port);OutputStream out=sock.getOutputStream()){
out.write(("String_Node_Str" + argument + "String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + PMS.get().usn()).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + 0).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str").getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.write(("String_Node_Str" + addr + "String_Node_Str"+ port).getBytes(StandardCharsets.UTF_8));
out.write(CRLF.getBytes(StandardCharsets.UTF_8));
out.flush();
}
 }
 catch (MalformedURLException ex) {
LOGGER.debug("String_Node_Str" + soapaction + "String_Node_Str",ex);
}
}
 else {
LOGGER.debug("String_Node_Str");
}
if (argument.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.eventHeader("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.EVENT_FOOTER);
}
 else if (argument.contains("String_Node_Str")) {
response.append(HTTPXMLHelper.eventHeader("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str"));
response.append(HTTPXMLHelper.eventProp("String_Node_Str","String_Node_Str" + DLNAResource.getSystemUpdateId()));
response.append(HTTPXMLHelper.EVENT_FOOTER);
}
}
 else if (method.equals("String_Node_Str")) {
output.headers().set(HttpHeaders.Names.CONTENT_TYPE,"String_Node_Str");
output.headers().set("String_Node_Str","String_Node_Str");
output.headers().set("String_Node_Str","String_Node_Str");
output.headers().set("String_Node_Str",PMS.get().usn());
output.headers().set("String_Node_Str","String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str").append(DLNAResource.getSystemUpdateId()).append("String_Node_Str");
response.append("String_Node_Str");
response.append("String_Node_Str");
}
output.headers().set("String_Node_Str",PMS.get().getServerName());
if (response.length() > 0) {
byte responseData[]=response.toString().getBytes("String_Node_Str");
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + responseData.length);
if (!method.equals("String_Node_Str")) {
ChannelBuffer buf=ChannelBuffers.copiedBuffer(responseData);
output.setContent(buf);
}
future=event.getChannel().write(output);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
 else if (inputStream != null) {
if (CLoverride > -2) {
if (CLoverride > -1 && CLoverride != DLNAMediaInfo.TRANS_SIZE) {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + CLoverride);
}
}
 else {
int contentLength=inputStream.available();
LOGGER.trace("String_Node_Str",contentLength);
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str" + contentLength);
}
if (range.isStartOffsetAvailable() && dlna != null) {
String timeseekValue=StringUtil.convertTimeToString(range.getStartOrZero(),StringUtil.DURATION_TIME_FORMAT);
String timetotalValue=dlna.getMedia().getDurationString();
String timeEndValue=range.isEndLimitAvailable() ? StringUtil.convertTimeToString(range.getEnd(),StringUtil.DURATION_TIME_FORMAT) : timetotalValue;
output.headers().set("String_Node_Str","String_Node_Str" + timeseekValue + "String_Node_Str"+ timeEndValue+ "String_Node_Str"+ timetotalValue);
output.headers().set("String_Node_Str","String_Node_Str" + timeseekValue + "String_Node_Str"+ timeEndValue+ "String_Node_Str"+ timetotalValue);
}
future=event.getChannel().write(output);
if (lowRange != DLNAMediaInfo.ENDFILE_POS && !method.equals("String_Node_Str")) {
ChannelFuture chunkWriteFuture=event.getChannel().write(new ChunkedStream(inputStream,BUFFER_SIZE));
chunkWriteFuture.addListener(new ChannelFutureListener(){
@Override public void operationComplete(ChannelFuture future){
try {
  inputStream.close();
}
 catch (IOException e) {
  LOGGER.error("String_Node_Str",e);
}
future.getChannel().close();
startStopListenerDelegate.stop();
}
}
);
}
 else {
try {
inputStream.close();
}
 catch (IOException ioe) {
LOGGER.error("String_Node_Str",ioe);
}
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
startStopListenerDelegate.stop();
}
}
 else {
output.headers().set(HttpHeaders.Names.CONTENT_LENGTH,"String_Node_Str");
output.setStatus(HttpResponseStatus.NO_CONTENT);
future=event.getChannel().write(output);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}
}
if (LOGGER.isTraceEnabled()) {
StringBuilder header=new StringBuilder();
for (Entry<String,String> entry : output.headers().entries()) {
if (isNotBlank(entry.getKey())) {
header.append("String_Node_Str").append(entry.getKey()).append("String_Node_Str").append(entry.getValue()).append("String_Node_Str");
}
}
String rendererName;
if (mediaRenderer != null) {
if (isNotBlank(mediaRenderer.getRendererName())) {
if (isBlank(mediaRenderer.getConfName()) || mediaRenderer.getRendererName().equals(mediaRenderer.getConfName())) {
rendererName=mediaRenderer.getRendererName();
}
 else {
rendererName=mediaRenderer.getRendererName() + "String_Node_Str" + mediaRenderer.getConfName()+ "String_Node_Str";
}
}
 else if (isNotBlank(mediaRenderer.getConfName())) {
rendererName=mediaRenderer.getConfName();
}
 else {
rendererName="String_Node_Str";
}
}
 else {
rendererName="String_Node_Str";
}
if (method.equals("String_Node_Str")) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header);
}
 else {
String formattedResponse=null;
if (isNotBlank(response)) {
try {
formattedResponse=StringUtil.prettifyXML(response.toString(),4);
}
 catch (SAXException|ParserConfigurationException|XPathExpressionException|TransformerException e) {
formattedResponse="String_Node_Str" + e.getMessage() + "String_Node_Str";
formattedResponse+="String_Node_Str" + response.toString().replaceAll("String_Node_Str","String_Node_Str");
}
}
if (isNotBlank(formattedResponse)) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header,formattedResponse);
Matcher matcher=DIDL_PATTERN.matcher(response);
if (matcher.find()) {
try {
  LOGGER.trace("String_Node_Str",rendererName,StringUtil.prettifyXML(StringEscapeUtils.unescapeXml(matcher.group(1)),2));
}
 catch (SAXException|ParserConfigurationException|XPathExpressionException|TransformerException e) {
  LOGGER.warn("String_Node_Str",e.getMessage());
  LOGGER.trace("String_Node_Str",e);
}
}
}
 else if (inputStream != null && !"String_Node_Str".equals(output.headers().get(HttpHeaders.Names.CONTENT_LENGTH))) {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),output.isChunked() ? "String_Node_Str" : "String_Node_Str",header);
}
 else {
LOGGER.trace("String_Node_Str",rendererName,output.getProtocolVersion(),output.getStatus(),header);
}
}
}
return future;
}