public void write(DataOutputStream out) throws IOException {
      for (String rootLogDir : this.rootLogDirs) {
        File appLogDir =
            new File(
                rootLogDir,
                ConverterUtils.toString(
                    this.containerId.getApplicationAttemptId().getApplicationId()));
        File containerLogDir = new File(appLogDir, ConverterUtils.toString(this.containerId));

        if (!containerLogDir.isDirectory()) {
          continue; // ContainerDir may have been deleted by the user.
        }

        // Write out log files in lexical order
        File[] logFiles = containerLogDir.listFiles();
        Arrays.sort(logFiles);
        for (File logFile : logFiles) {

          // Write the logFile Type
          out.writeUTF(logFile.getName());

          // Write the log length as UTF so that it is printable
          out.writeUTF(String.valueOf(logFile.length()));

          // Write the log itself
          FileInputStream in = null;
          try {
            in = SecureIOUtils.openForRead(logFile, getUser(), null);
            byte[] buf = new byte[65535];
            int len = 0;
            while ((len = in.read(buf)) != -1) {
              out.write(buf, 0, len);
            }
          } catch (IOException e) {
            String message =
                "Error aggregating log file. Log file : "
                    + logFile.getAbsolutePath()
                    + e.getMessage();
            LOG.error(message, e);
            out.write(message.getBytes());
          } finally {
            if (in != null) {
              in.close();
            }
          }
        }
      }
    }
 public AppAttemptInfo(RMAppAttempt attempt) {
   this.startTime = 0;
   this.containerId = "";
   this.nodeHttpAddress = "";
   this.nodeId = "";
   this.logsLink = "";
   if (attempt != null) {
     this.id = attempt.getAppAttemptId().getAttemptId();
     this.startTime = attempt.getStartTime();
     Container masterContainer = attempt.getMasterContainer();
     if (masterContainer != null) {
       this.containerId = masterContainer.getId().toString();
       this.nodeHttpAddress = masterContainer.getNodeHttpAddress();
       this.nodeId = masterContainer.getNodeId().toString();
       this.logsLink =
           join(
               HttpConfig.getSchemePrefix(),
               masterContainer.getNodeHttpAddress(),
               "/node",
               "/containerlogs/",
               ConverterUtils.toString(masterContainer.getId()),
               "/",
               attempt.getSubmissionContext().getUser());
     }
   }
 }
 @Override
 public String toString() {
   this.readLock.lock();
   try {
     return ConverterUtils.toString(this.containerId);
   } finally {
     this.readLock.unlock();
   }
 }
 public AppLogAggregatorImpl(
     Dispatcher dispatcher,
     DeletionService deletionService,
     Configuration conf,
     ApplicationId appId,
     UserGroupInformation userUgi,
     LocalDirsHandlerService dirsHandler,
     Path remoteNodeLogFileForApp,
     ContainerLogsRetentionPolicy retentionPolicy,
     Map<ApplicationAccessType, String> appAcls) {
   this.dispatcher = dispatcher;
   this.conf = conf;
   this.delService = deletionService;
   this.appId = appId;
   this.applicationId = ConverterUtils.toString(appId);
   this.userUgi = userUgi;
   this.dirsHandler = dirsHandler;
   this.remoteNodeLogFileForApp = remoteNodeLogFileForApp;
   this.remoteNodeTmpLogFileForApp = getRemoteNodeTmpLogFileForApp();
   this.retentionPolicy = retentionPolicy;
   this.pendingContainers = new LinkedBlockingQueue<ContainerId>();
   this.appAcls = appAcls;
 }