Skip to content

Instantly share code, notes, and snippets.

View team172011's full-sized avatar
🎯
Focusing

Simon team172011

🎯
Focusing
View GitHub Profile
@team172011
team172011 / modena.css
Created October 24, 2017 16:30 — forked from maxd/modena.css
modena.css from jdk1.8.0_91
/*
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
@team172011
team172011 / awtTojavaFxColor.java
Created January 5, 2018 10:29
java.awt.Color to javafx.scene.paint.Color
import java.awt.Color;
/**
* Returns a javaFX Color object that represents the same color as the awt color object
* @param c a java.awt.Color object
*/
private javafx.scene.paint.Color awtColorToJavaFX(Color c) {
return javafx.scene.paint.Color.rgb(c.getRed(), c.getGreen(), c.getBlue(), c.getAlpha() / 255.0);
}
@team172011
team172011 / InputStreamToString.java
Last active June 24, 2019 07:27
Write the content of a file (InputStream) to an String variable
public static String getFileContent(FileInputStream fis, String encoding ) throws IOException{
try(BufferedReader br =new BufferedReader(new InputStreamReader(fis, encoding))){
StringBuilder sb = new StringBuilder();
String line;
while(( line = br.readLine()) != null ) {
sb.append( line );
sb.append( '\n' );
}
return sb.toString();
}
@team172011
team172011 / deleteDirRecursive.java
Created October 17, 2019 15:52
Delete a folder in java
public static void deleteDirRecursive(File folder) {
File[] files = folder.listFiles();
if (files != null) {
for (File f : files) {
if (f.isDirectory()) {
deleteDirRecursive(f);
} else {
f.delete();
}
}
@team172011
team172011 / unzipToParentDir.java
Created October 17, 2019 15:53
Unzip a zip file with all zip entries in java
private void unzipToParentDir(File file) throws IOException {
try (ZipFile zipFile = new ZipFile(file)) {
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
File entryDestination = new File(file.getParent(), entry.getName());
if (entry.isDirectory()) {
entryDestination.mkdirs();
} else {
entryDestination.getParentFile().mkdirs();
@team172011
team172011 / createZipAsByteArray.java
Created October 17, 2019 15:55
Create a zip file with several entries
private byte[] createZipAsByteArray(Path path, Map<String, File> files) throws IOException {
String pathToZip = path.toString()+File.separator+"content.zip";
FileOutputStream fileOutputStream = new FileOutputStream(pathToZip);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream);
byte[] buffer = new byte[1024];
int len;
for(Map.Entry<String, File> file: files.entrySet()) {
FileInputStream fileInputStream2 = new FileInputStream(file.getValue());
ZipEntry zipEntry = new ZipEntry(file.getKey());
zipOutputStream.putNextEntry(zipEntry);
@team172011
team172011 / FileUploadJersey.java
Created November 29, 2019 15:30
FileUpload with Jersey/Javax
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.StreamingOutput;
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.core.StreamingOutput;
@POST
@Path(value = "/fileUpload")
@team172011
team172011 / FileUploadSpring.java
Created November 29, 2019 15:38
Fileupload with Spring
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
@PostMapping(value= "/projects/{name}/upload", consumes = { "multipart/form-data" })
ResponseEntity<String> addConfigurationAsXml(@PathVariable String name, @RequestPart("file") MultipartFile upfile){
byte[] bytes = upfile.getBytes();
return new ResponseEntity<>("Done..", HttpStatus.OK)
}
@team172011
team172011 / ZonedDateTimeToUtilDate.java
Last active September 5, 2020 10:07
java.time.ZonedDateTime to java.util.Date
java.time.ZonedDateTime myZonedDateTime = java.time.ZonedDateTime.now();
java.util.Date date = java.util.Date.from(myZonedDateTime.toInstant());
@team172011
team172011 / XMLAdapter.java
Last active March 24, 2022 09:02
XmlAdapter for String to XML
import java.io.IOException;
import java.io.StringReader;
import java.io.StringWriter;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.w3c.dom.Document;