Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright (c) 2018 by Andrew Charneski.
*
* The author licenses this file to you under the
* Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.simiacryptus.util.io;
import com.simiacryptus.util.FileNanoHTTPD;
import com.simiacryptus.util.TableOutput;
import com.simiacryptus.util.Util;
import com.simiacryptus.util.lang.CodeUtil;
import com.simiacryptus.util.lang.TimedResult;
import com.simiacryptus.util.lang.UncheckedSupplier;
import com.simiacryptus.util.test.SysOutInterceptor;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.annotation.Nullable;
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.lang.management.ManagementFactory;
import java.net.URI;
import java.nio.charset.Charset;
import java.util.Base64;
import java.util.UUID;
/**
* The type Html notebook output.
*/
@Deprecated
public class HtmlNotebookOutput implements NotebookOutput {
private static final Logger log = LoggerFactory.getLogger(com.simiacryptus.util.io.HtmlNotebookOutput.class);
/**
* The constant DEFAULT_ROOT.
*/
@javax.annotation.Nonnull
public static String DEFAULT_ROOT = "https://github.com/SimiaCryptus/utilities/tree/master/";
/**
* The Working dir.
*/
public final File workingDir;
@javax.annotation.Nonnull
private final PrintStream primaryOut;
private int maxOutSize = 8 * 1024;
private int maxImageSize = 1600;
/**
* The Source root.
*/
public String sourceRoot = com.simiacryptus.util.io.HtmlNotebookOutput.DEFAULT_ROOT;
/**
* The Excerpt number.
*/
int excerptNumber = 0;
/**
* Instantiates a new Html notebook output.
*
* @param parentDirectory the parent directory
* @param out the out
*/
public HtmlNotebookOutput(final File parentDirectory, @javax.annotation.Nonnull final OutputStream out) {
primaryOut = new PrintStream(out);
workingDir = parentDirectory;
out("");
}
/**
* Create html notebook output.
*
* @param parentDirectory the parent directory
* @return the html notebook output
* @throws FileNotFoundException the file not found exception
*/
public static com.simiacryptus.util.io.HtmlNotebookOutput create(final File parentDirectory) throws FileNotFoundException {
@javax.annotation.Nonnull final FileOutputStream out = new FileOutputStream(new File(parentDirectory, "index.html"));
return new com.simiacryptus.util.io.HtmlNotebookOutput(parentDirectory, out) {
@Override
public void close() throws IOException {
out.close();
}
};
}
@Override
public void close() throws IOException {
out("");
if (null != primaryOut) {
primaryOut.close();
}
}
@javax.annotation.Nonnull
@SuppressWarnings("unchecked")
@Override
public T code(@javax.annotation.Nonnull final UncheckedSupplier fn, final int maxLog, final int framesNo) {
try {
final StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
final StackTraceElement callingFrame = stackTrace[framesNo];
final String sourceCode = CodeUtil.getInnerText(callingFrame);
@javax.annotation.Nonnull final SysOutInterceptor.LoggedResult> result = SysOutInterceptor.withOutput(() -> {
long priorGcMs = ManagementFactory.getGarbageCollectorMXBeans().stream().mapToLong(x -> x.getCollectionTime()).sum();
final long start = System.nanoTime();
try {
@Nullable Object result1 = null;
try {
result1 = fn.get();
} catch (@javax.annotation.Nonnull final RuntimeException e) {
throw e;
} catch (@javax.annotation.Nonnull final Exception e) {
throw new RuntimeException(e);
}
long gcTime = ManagementFactory.getGarbageCollectorMXBeans().stream().mapToLong(x -> x.getCollectionTime()).sum() - priorGcMs;
return new TimedResult