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();
}
}
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"));
}
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."));
}
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;
}
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);
}
Aggregations