Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git
src/main/java/com/keenwrite/io/StreamMediaType.java
import java.io.IOException;
import java.io.InputStream;
+import java.nio.file.Path;
import java.util.LinkedHashMap;
import java.util.Map;
private StreamMediaType() {
+ }
+
+ public static MediaType getMediaType( final Path path ) throws IOException {
+ return getMediaType( path.toFile() );
}
src/main/java/com/keenwrite/processors/XhtmlProcessor.java
package com.keenwrite.processors;
+import com.keenwrite.io.StreamMediaType;
import com.keenwrite.preferences.Workspace;
import static java.lang.String.format;
import static java.nio.file.Files.copy;
+import static java.nio.file.Files.move;
import static java.nio.file.StandardCopyOption.REPLACE_EXISTING;
import static java.util.regex.Pattern.UNICODE_CHARACTER_CLASS;
final var contentType = conn.getContentType();
- final var mediaType = valueFrom( contentType );
+ var mediaType = valueFrom( contentType );
+
imageFile = mediaType.createTemporaryFile( APP_TITLE_LOWERCASE );
- try( final var svgIn = conn.getInputStream() ) {
- copy( svgIn, imageFile, REPLACE_EXISTING );
+ try( final var image = conn.getInputStream() ) {
+ copy( image, imageFile, REPLACE_EXISTING );
}
conn.disconnect();
+
+ if( mediaType.isUndefined() ) {
+ mediaType = StreamMediaType.getMediaType( imageFile );
+ final var file = mediaType.createTemporaryFile( APP_TITLE_LOWERCASE );
+ move( imageFile, file, REPLACE_EXISTING );
+ imageFile = file;
+ }
// Strip comments, superfluous whitespace, DOCTYPE, and XML declarations.

Autodetect unknown file format

Author DaveJarvis <email>
Date 2021-04-04 02:49:19 GMT-0700
Commit cd4692f02b8437903e0f3a37b9783766c26115f4
Parent bbd3e1d
Delta 18 lines added, 3 lines removed, 15-line increase