This repository has been archived on 2022-02-10. You can view files and clone it, but cannot push or open issues or pull requests.
morse-converter/src/de/marcelkapfer/c/morseconverter/update/Update.java
2015-06-02 17:25:06 +02:00

76 lines
2.5 KiB
Java

package de.marcelkapfer.c.morseconverter.update;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.file.Files;
import java.util.logging.FileHandler;
/*
This is a Java application for converting writtenMorse and normal morse code.
Copyright (C) 2014-2015 Marcel Michael Kapfer
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
Marcel Michael Kapfer
marcelmichaelkapfer@yahoo.co.nz
*/
public class Update {
private static URL update;
public static boolean isConnected(String url){
try {
update = new URL(url);
update.openStream();
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static boolean update(String path, String filename){
try {
ReadableByteChannel updateChannel = Channels.newChannel(update.openStream());
FileOutputStream updateOutputStream = new FileOutputStream(path + filename);
updateOutputStream.getChannel().transferFrom(updateChannel, 0, Long.MAX_VALUE);
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
public static int getLatestVersion(String versionFile, int currentVersion){
int latestVersion = currentVersion;
try {
URL versionURL = new URL(versionFile);
BufferedReader versionReader = new BufferedReader(new InputStreamReader(versionURL.openStream()));
latestVersion = Integer.valueOf(versionReader.readLine());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return latestVersion;
}
}