Search in sources :

Example 1 with Element

use of com.zhan_dui.utils.m3u8.Element in project AnimeTaste by daimajia.

the class M3U8Mission method run.

@Override
public void run() {
    notifyStart();
    BufferedInputStream in = null;
    FileOutputStream out = null;
    HttpURLConnection httpURLConnection;
    try {
        httpURLConnection = (HttpURLConnection) new URL(getUri()).openConnection();
        in = new BufferedInputStream(httpURLConnection.getInputStream());
        out = getSafeOutputStream(getSaveDir(), getSaveName());
        mM3U8Playlist = Playlist.parse(in);
        for (Element el : mM3U8Playlist) {
            mTotalVideoDuration += el.getDuration();
        }
        mVideoSegmentCount = mM3U8Playlist.getElements().size();
        notifyMetaDataReady();
        byte[] data = new byte[1024];
        int count;
        int c = 0;
        for (Element el : mM3U8Playlist) {
            HttpURLConnection connection = (HttpURLConnection) new URL(el.getURI().toString()).openConnection();
            connection.setConnectTimeout(5000);
            in = new BufferedInputStream(connection.getInputStream());
            while (isCanceled() == false) {
                try {
                    count = in.read(data, 0, 1024);
                    if (count == -1) {
                        break;
                    }
                    out.write(data, 0, count);
                    mCurrentPartDownloaded += count;
                    mDownloaded += count;
                    notifySpeedChange();
                    checkPaused();
                } catch (Exception e) {
                    //if pause download, it will makes the socket close,and stop the download.
                    //so we need to reopen it.
                    //well, maybe a big bug here, maybe cause dead cycle :( so I set a
                    //max open count to prevent this situation.
                    mReopenCount++;
                    if (mReopenCount > MAX_REOPEN_COUNT) {
                        throw new Exception("There is too much open exception.");
                    }
                    connection = (HttpURLConnection) new URL(el.getURI().toString()).openConnection();
                    connection.setRequestProperty("Range", "bytes=" + mCurrentPartDownloaded + "-");
                    connection.setDoOutput(true);
                    connection.setDoInput(true);
                    in = new BufferedInputStream(connection.getInputStream());
                }
            }
            mCurrentPartDownloaded = 0;
            mDownloadedSgementCount++;
            mDownloadedVideoDuration += el.getDuration();
            notifyPercentageChange();
            if (isCanceled()) {
                notifyCancel();
                break;
            }
        }
        if (!isCanceled()) {
            notifyPercentageChange();
            notifySuccess();
        }
    } catch (Exception e) {
        notifyError(e);
    } finally {
        try {
            if (in != null)
                in.close();
            if (out != null)
                out.close();
        } catch (Exception e) {
            notifyError(e);
        }
        notifyFinish();
    }
}
Also used : HttpURLConnection(java.net.HttpURLConnection) BufferedInputStream(java.io.BufferedInputStream) FileOutputStream(java.io.FileOutputStream) Element(com.zhan_dui.utils.m3u8.Element) URL(java.net.URL)

Example 2 with Element

use of com.zhan_dui.utils.m3u8.Element in project gocd by gocd.

the class DirectoryEntriesTest method shouldReturnAMessageWhenThereAreNoArtifacts.

@Test
public void shouldReturnAMessageWhenThereAreNoArtifacts() throws Exception {
    HtmlRenderer renderer = new HtmlRenderer("context");
    DirectoryEntries directoryEntries = new DirectoryEntries();
    directoryEntries.add(new FolderDirectoryEntry("cruise-output", "", new DirectoryEntries()));
    directoryEntries.setIsArtifactsDeleted(true);
    directoryEntries.render(renderer);
    Element document = getRenderedDocument(renderer);
    assertThat(document.getChildren().size(), is(2));
    assertThat(document.getChild("p").getTextNormalize(), Matchers.containsString("Artifacts for this job instance are unavailable as they may have been or deleted externally. Re-run the stage or job to generate them again."));
    assertThat(document.getChild("ul").getChild("div").getChild("span").getChild("a").getTextNormalize(), is("cruise-output"));
}
Also used : Element(org.jdom2.Element) HtmlRenderer(com.thoughtworks.go.server.presentation.models.HtmlRenderer) Test(org.junit.Test)

Example 3 with Element

use of com.zhan_dui.utils.m3u8.Element in project gocd by gocd.

the class DirectoryEntriesTest method shouldReturnAMessageWhenAllArtifactsHaveBeenDeletedButArtifactsDeletedFlagHasNotBeenSet.

@Test
public void shouldReturnAMessageWhenAllArtifactsHaveBeenDeletedButArtifactsDeletedFlagHasNotBeenSet() throws Exception {
    HtmlRenderer renderer = new HtmlRenderer("context");
    DirectoryEntries directoryEntries = new DirectoryEntries();
    directoryEntries.render(renderer);
    Element document = getRenderedDocument(renderer);
    assertThat(document.getChildren().size(), is(1));
    assertThat(document.getChild("p").getTextNormalize(), Matchers.containsString("Artifacts for this job instance are unavailable as they may have been or deleted externally. Re-run the stage or job to generate them again."));
}
Also used : Element(org.jdom2.Element) HtmlRenderer(com.thoughtworks.go.server.presentation.models.HtmlRenderer) Test(org.junit.Test)

Example 4 with Element

use of com.zhan_dui.utils.m3u8.Element in project gocd by gocd.

the class BuildWork method execute.

private JobResult execute(EnvironmentVariableContext environmentVariableContext) {
    Date now = new Date();
    // collect project information
    // TODO - #2409
    buildLog.addContent(new Element("info"));
    JobResult result = builders.build(environmentVariableContext);
    goPublisher.reportCompleting(result);
    try {
        buildLog.writeLogFile(now);
    } catch (IOException e) {
        throw bomb("Failed to write log file", e);
    }
    buildLog.reset();
    return result;
}
Also used : Element(org.jdom2.Element) IOException(java.io.IOException) Date(java.util.Date)

Example 5 with Element

use of com.zhan_dui.utils.m3u8.Element in project gocd by gocd.

the class GoControlLog method writeLogFile.

/**
     * Writes the current build log to the appropriate directory and filename.
     */
public void writeLogFile(Date now) throws IOException {
    String logFilename = decideLogfileName(now);
    // Add the logDir as an info element
    Element logDirElement = new Element("property");
    logDirElement.setAttribute("name", "logdir");
    logDirElement.setAttribute("value", new File(logDir).getAbsolutePath());
    buildLog.getChild("info").addContent(logDirElement);
    // Add the logFile as an info element
    Element logFileElement = new Element("property");
    logFileElement.setAttribute("name", "logfile");
    logFileElement.setAttribute("value", logFilename);
    buildLog.getChild("info").addContent(logFileElement);
    File logfile = new File(logDir, logFilename);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Writing log file [" + logfile.getAbsolutePath() + "]");
    }
    writeLogFile(logfile, buildLog);
}
Also used : Element(org.jdom2.Element) File(java.io.File)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)73 Document (org.jdom2.Document)58 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 IOException (java.io.IOException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 Dimension (java.awt.Dimension)14 FileNotFoundException (java.io.FileNotFoundException)13 SignalHead (jmri.SignalHead)13 List (java.util.List)12