Program: 47042
Project: 47042
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 output The {@link HttpResponse} object that will be used to construct the response.
 * @param startStopListenerDelegate The {@link StartStopListenerDelegate} object that is usedto notify plugins that the  {@link DLNAResource} is about to start playing.
 * @throws IOException
 */
public void answer(OutputStream output,StartStopListenerDelegate startStopListenerDelegate) throws IOException {
  this.output=output;
  List<String> responseHeader=new ArrayList<>();
  long CLoverride=-2;
  if (lowRange != 0 || highRange != 0) {
    appendToHeader(responseHeader,http10 ? HTTP_206_OK_10 : HTTP_206_OK);
  }
 else {
    if (soapaction != null && soapaction.contains("String_Node_Str")) {
      appendToHeader(responseHeader,http10 ? HTTP_500_10 : HTTP_500);
    }
 else {
      appendToHeader(responseHeader,http10 ? HTTP_200_OK_10 : HTTP_200_OK);
    }
  }
  StringBuilder response=new StringBuilder();
  DLNAResource dlna=null;
  boolean xbox360=(mediaRenderer == null ? false : 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")) {
    appendToHeader(responseHeader,"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) {
      appendToHeader(responseHeader,"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);
        appendToHeader(responseHeader,"String_Node_Str" + imageProfile.getMimeType());
        appendToHeader(responseHeader,"String_Node_Str");
        appendToHeader(responseHeader,"String_Node_Str" + getFUTUREDATE() + "String_Node_Str");
        appendToHeader(responseHeader,"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);
        if (contentFeatures != null) {
          appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(imageProfile,true));
        }
        if (inputStream != null && (lowRange > 0 || highRange > 0)) {
          if (lowRange > 0) {
            inputStream.skip(lowRange);
          }
          inputStream=DLNAResource.wrap(inputStream,highRange,lowRange);
        }
        appendToHeader(responseHeader,"String_Node_Str");
        appendToHeader(responseHeader,"String_Node_Str");
      }
 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;
}
}
appendToHeader(responseHeader,"String_Node_Str" + imageProfile.getMimeType());
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + getFUTUREDATE() + "String_Node_Str");
appendToHeader(responseHeader,"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);
  if (contentFeatures != null) {
    appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(imageProfile,false));
  }
  if (inputStream != null && (lowRange > 0 || highRange > 0)) {
    if (lowRange > 0) {
      inputStream.skip(lowRange);
    }
    inputStream=DLNAResource.wrap(inputStream,highRange,lowRange);
  }
  appendToHeader(responseHeader,"String_Node_Str");
  appendToHeader(responseHeader,"String_Node_Str");
}
}
 catch (IOException e) {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
responseHeader.set(0,http10 ? HTTP_415_UNSUPPORTED_MEDIA_TYPE_10 : HTTP_415_UNSUPPORTED_MEDIA_TYPE);
sendHeader(responseHeader);
LOGGER.debug("String_Node_Str",dlna.getName(),e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName());
LOGGER.trace("String_Node_Str",e);
return;
}
}
 else if (dlna.getMedia() != null && fileName.contains("String_Node_Str") && dlna.isCodeValid(dlna)) {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + 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);
}
String name=dlna.getDisplayName(mediaRenderer);
if (dlna.isNoName()) {
name=dlna.getName() + "String_Node_Str" + dlna.getDisplayName(mediaRenderer);
}
inputStream=dlna.getInputStream(Range.create(lowRange,highRange,timeseek,timeRangeEnd),mediaRenderer);
if (dlna.isResume()) {
timeseek=dlna.getResume().getTimeOffset() / (double)1000;
}
if (inputStream == null) {
LOGGER.error("String_Node_Str" + name);
}
 else {
startStopListenerDelegate.start(dlna);
appendToHeader(responseHeader,"String_Node_Str" + getRendererMimeType(dlna.mimeType(),mediaRenderer,dlna.getMedia()));
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;
    appendToHeader(responseHeader,subtitleHttpHeader + "String_Node_Str" + 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));
}
boolean chunked=mediaRenderer.isChunkedTransfer();
long totalsize=dlna.length(mediaRenderer);
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");
  appendToHeader(responseHeader,"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;
}
if (contentFeatures != null) {
  appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(mediaRenderer));
}
if (dlna.getPlayer() == null || xbox360) {
  appendToHeader(responseHeader,"String_Node_Str");
}
appendToHeader(responseHeader,"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")) {
appendToHeader(responseHeader,"String_Node_Str");
}
 else {
appendToHeader(responseHeader,"String_Node_Str");
}
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + 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"))) {
appendToHeader(responseHeader,CONTENT_TYPE);
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"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());
}
inputStream=new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
}
}
 else if (method.equals("String_Node_Str") && (argument.contains("String_Node_Str") || argument.contains("String_Node_Str"))) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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")) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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.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.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.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;
}
}
Object sI=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
Object 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.toString());
}
if (rC != null) {
requestCount=Integer.parseInt(rC.toString());
}
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)) || files.get(0).getParent() instanceof FileTranscodeVirtualFolder) {
  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();
}
 else {
parentFolder=PMS.get().getRootFolder(mediaRenderer).getDLNAResource(objectID,mediaRenderer);
}
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")) {
if (soapaction == null) {
return;
}
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().usn());
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().getServerName());
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
responseHeader.clear();
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();
sendLine(out,"String_Node_Str" + argument + "String_Node_Str");
sendLine(out,"String_Node_Str" + PMS.get().usn());
sendLine(out,"String_Node_Str" + 0);
sendLine(out,"String_Node_Str");
sendLine(out,"String_Node_Str");
sendLine(out,"String_Node_Str" + addr + "String_Node_Str"+ port);
sendLine(out,CONTENT_TYPE_UTF8);
}
 }
 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);
}
}
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().getServerName());
if (response.length() > 0) {
byte responseData[]=response.toString().getBytes("String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + responseData.length);
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
if (!method.equals("String_Node_Str")) {
output.write(responseData);
}
}
 else if (inputStream != null) {
if (CLoverride > -2) {
if (CLoverride > -1 && CLoverride != DLNAMediaInfo.TRANS_SIZE) {
appendToHeader(responseHeader,"String_Node_Str" + CLoverride);
}
}
 else {
int cl=inputStream.available();
LOGGER.trace("String_Node_Str" + cl);
appendToHeader(responseHeader,"String_Node_Str" + cl);
}
if (timeseek > 0 && dlna != null) {
String timeseekValue=StringUtil.formatDLNADuration(timeseek);
String timetotalValue=dlna.getMedia().getDurationString();
appendToHeader(responseHeader,"String_Node_Str" + timeseekValue + "String_Node_Str"+ timetotalValue+ "String_Node_Str"+ timetotalValue);
appendToHeader(responseHeader,"String_Node_Str" + timeseekValue + "String_Node_Str"+ timetotalValue+ "String_Node_Str"+ timetotalValue);
}
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
long sendB=0;
if (lowRange != DLNAMediaInfo.ENDFILE_POS && !method.equals("String_Node_Str")) {
sendB=sendBytes(inputStream);
}
if (sendB > -1) {
LOGGER.trace("String_Node_Str",sendB,argument);
}
 else {
startStopListenerDelegate.stop();
}
}
 else {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
responseHeader.set(0,http10 ? HTTP_204_NO_CONTENT_10 : HTTP_204_NO_CONTENT);
sendHeader(responseHeader);
}
if (LOGGER.isTraceEnabled()) {
StringBuilder header=new StringBuilder();
for (int i=0; i < responseHeader.size(); i++) {
if (isNotBlank(responseHeader.get(i))) {
header.append("String_Node_Str").append(responseHeader.get(i)).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,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,header,formattedResponse);
Matcher matcher=DIDL_PATTERN.matcher(response);
if (matcher.find()) {
try {
  LOGGER.trace("String_Node_Str",mediaRenderer.getConfName(),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 && !responseHeader.contains("String_Node_Str")) {
LOGGER.trace("String_Node_Str",rendererName,header);
}
 else {
LOGGER.trace("String_Node_Str",rendererName,header);
}
}
}
}

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 output The {@link HttpResponse} object that will be used to construct the response.
 * @param startStopListenerDelegate The {@link StartStopListenerDelegate} object that is usedto notify plugins that the  {@link DLNAResource} is about to start playing.
 * @throws IOException
 */
public void answer(OutputStream output,StartStopListenerDelegate startStopListenerDelegate) throws IOException {
  this.output=output;
  List<String> responseHeader=new ArrayList<>();
  long CLoverride=-2;
  if (lowRange != 0 || highRange != 0) {
    appendToHeader(responseHeader,http10 ? HTTP_206_OK_10 : HTTP_206_OK);
  }
 else {
    if (soapaction != null && soapaction.contains("String_Node_Str")) {
      appendToHeader(responseHeader,http10 ? HTTP_500_10 : HTTP_500);
    }
 else {
      appendToHeader(responseHeader,http10 ? HTTP_200_OK_10 : HTTP_200_OK);
    }
  }
  StringBuilder response=new StringBuilder();
  DLNAResource dlna=null;
  boolean xbox360=(mediaRenderer == null ? false : 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")) {
    appendToHeader(responseHeader,"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) {
      appendToHeader(responseHeader,"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);
        appendToHeader(responseHeader,"String_Node_Str" + imageProfile.getMimeType());
        appendToHeader(responseHeader,"String_Node_Str");
        appendToHeader(responseHeader,"String_Node_Str" + getFUTUREDATE() + "String_Node_Str");
        appendToHeader(responseHeader,"String_Node_Str");
        DLNAThumbnailInputStream thumbInputStream;
        if (!configuration.isShowCodeThumbs() && !dlna.isCodeValid(dlna)) {
          thumbInputStream=dlna.getGenericThumbnailInputStream(null);
        }
 else {
          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);
        if (contentFeatures != null) {
          appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(imageProfile,true));
        }
        if (inputStream != null && (lowRange > 0 || highRange > 0)) {
          if (lowRange > 0) {
            inputStream.skip(lowRange);
          }
          inputStream=DLNAResource.wrap(inputStream,highRange,lowRange);
        }
        appendToHeader(responseHeader,"String_Node_Str");
        appendToHeader(responseHeader,"String_Node_Str");
      }
 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;
}
}
appendToHeader(responseHeader,"String_Node_Str" + imageProfile.getMimeType());
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + getFUTUREDATE() + "String_Node_Str");
appendToHeader(responseHeader,"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);
  if (contentFeatures != null) {
    appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(imageProfile,false));
  }
  if (inputStream != null && (lowRange > 0 || highRange > 0)) {
    if (lowRange > 0) {
      inputStream.skip(lowRange);
    }
    inputStream=DLNAResource.wrap(inputStream,highRange,lowRange);
  }
  appendToHeader(responseHeader,"String_Node_Str");
  appendToHeader(responseHeader,"String_Node_Str");
}
}
 catch (IOException e) {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
responseHeader.set(0,http10 ? HTTP_415_UNSUPPORTED_MEDIA_TYPE_10 : HTTP_415_UNSUPPORTED_MEDIA_TYPE);
sendHeader(responseHeader);
LOGGER.debug("String_Node_Str",dlna.getName(),e.getMessage() != null ? e.getMessage() : e.getClass().getSimpleName());
LOGGER.trace("String_Node_Str",e);
return;
}
}
 else if (dlna.getMedia() != null && fileName.contains("String_Node_Str") && dlna.isCodeValid(dlna)) {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + 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);
}
String name=dlna.getDisplayName(mediaRenderer);
if (dlna.isNoName()) {
name=dlna.getName() + "String_Node_Str" + dlna.getDisplayName(mediaRenderer);
}
inputStream=dlna.getInputStream(Range.create(lowRange,highRange,timeseek,timeRangeEnd),mediaRenderer);
if (dlna.isResume()) {
timeseek=dlna.getResume().getTimeOffset() / (double)1000;
}
if (inputStream == null) {
LOGGER.error("String_Node_Str" + name);
}
 else {
startStopListenerDelegate.start(dlna);
appendToHeader(responseHeader,"String_Node_Str" + getRendererMimeType(dlna.mimeType(),mediaRenderer,dlna.getMedia()));
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;
    appendToHeader(responseHeader,subtitleHttpHeader + "String_Node_Str" + 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));
}
boolean chunked=mediaRenderer.isChunkedTransfer();
long totalsize=dlna.length(mediaRenderer);
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");
  appendToHeader(responseHeader,"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;
}
if (contentFeatures != null) {
  appendToHeader(responseHeader,"String_Node_Str" + dlna.getDlnaContentFeatures(mediaRenderer));
}
if (dlna.getPlayer() == null || xbox360) {
  appendToHeader(responseHeader,"String_Node_Str");
}
appendToHeader(responseHeader,"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")) {
appendToHeader(responseHeader,"String_Node_Str");
}
 else {
appendToHeader(responseHeader,"String_Node_Str");
}
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + 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"))) {
appendToHeader(responseHeader,CONTENT_TYPE);
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"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());
}
inputStream=new ByteArrayInputStream(s.getBytes(StandardCharsets.UTF_8));
}
}
 else if (method.equals("String_Node_Str") && (argument.contains("String_Node_Str") || argument.contains("String_Node_Str"))) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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.SOAP_ENCODING_FOOTER);
response.append(CRLF);
}
 else if (method.equals("String_Node_Str") && argument.endsWith("String_Node_Str")) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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")) {
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
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.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.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.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;
}
}
Object sI=getEnclosingValue(content,"String_Node_Str","String_Node_Str");
Object 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.toString());
}
if (rC != null) {
requestCount=Integer.parseInt(rC.toString());
}
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)) || files.get(0).getParent() instanceof FileTranscodeVirtualFolder) {
  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();
}
 else {
parentFolder=PMS.get().getRootFolder(mediaRenderer).getDLNAResource(objectID,mediaRenderer);
}
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")) {
if (soapaction == null) {
return;
}
appendToHeader(responseHeader,CONTENT_TYPE_UTF8);
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().usn());
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().getServerName());
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
responseHeader.clear();
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();
sendLine(out,"String_Node_Str" + argument + "String_Node_Str");
sendLine(out,"String_Node_Str" + PMS.get().usn());
sendLine(out,"String_Node_Str" + 0);
sendLine(out,"String_Node_Str");
sendLine(out,"String_Node_Str");
sendLine(out,"String_Node_Str" + addr + "String_Node_Str"+ port);
sendLine(out,CONTENT_TYPE_UTF8);
}
 }
 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);
}
}
appendToHeader(responseHeader,"String_Node_Str" + PMS.get().getServerName());
if (response.length() > 0) {
byte responseData[]=response.toString().getBytes("String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str" + responseData.length);
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
if (!method.equals("String_Node_Str")) {
output.write(responseData);
}
}
 else if (inputStream != null) {
if (CLoverride > -2) {
if (CLoverride > -1 && CLoverride != DLNAMediaInfo.TRANS_SIZE) {
appendToHeader(responseHeader,"String_Node_Str" + CLoverride);
}
}
 else {
int cl=inputStream.available();
LOGGER.trace("String_Node_Str" + cl);
appendToHeader(responseHeader,"String_Node_Str" + cl);
}
if (timeseek > 0 && dlna != null) {
String timeseekValue=StringUtil.formatDLNADuration(timeseek);
String timetotalValue=dlna.getMedia().getDurationString();
appendToHeader(responseHeader,"String_Node_Str" + timeseekValue + "String_Node_Str"+ timetotalValue+ "String_Node_Str"+ timetotalValue);
appendToHeader(responseHeader,"String_Node_Str" + timeseekValue + "String_Node_Str"+ timetotalValue+ "String_Node_Str"+ timetotalValue);
}
appendToHeader(responseHeader,"String_Node_Str");
sendHeader(responseHeader);
long sendB=0;
if (lowRange != DLNAMediaInfo.ENDFILE_POS && !method.equals("String_Node_Str")) {
sendB=sendBytes(inputStream);
}
if (sendB > -1) {
LOGGER.trace("String_Node_Str",sendB,argument);
}
 else {
startStopListenerDelegate.stop();
}
}
 else {
appendToHeader(responseHeader,"String_Node_Str");
appendToHeader(responseHeader,"String_Node_Str");
responseHeader.set(0,http10 ? HTTP_204_NO_CONTENT_10 : HTTP_204_NO_CONTENT);
sendHeader(responseHeader);
}
if (LOGGER.isTraceEnabled()) {
StringBuilder header=new StringBuilder();
for (int i=0; i < responseHeader.size(); i++) {
if (isNotBlank(responseHeader.get(i))) {
header.append("String_Node_Str").append(responseHeader.get(i)).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,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,header,formattedResponse);
Matcher matcher=DIDL_PATTERN.matcher(response);
if (matcher.find()) {
try {
  LOGGER.trace("String_Node_Str",mediaRenderer.getConfName(),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 && !responseHeader.contains("String_Node_Str")) {
LOGGER.trace("String_Node_Str",rendererName,header);
}
 else {
LOGGER.trace("String_Node_Str",rendererName,header);
}
}
}
}