This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright (c) 2009, 2015, Oracle and/or its affiliates. All rights reserved. | |
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms. | |
* | |
* | |
* | |
* | |
* | |
* | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java.time.ZonedDateTime myZonedDateTime = java.time.ZonedDateTime.now(); | |
java.util.Date date = java.util.Date.from(myZonedDateTime.toInstant()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
OlderNewer