created class SibaUtils + issues
This commit is contained in:
parent
3db3897512
commit
dfa6b2dcf6
@ -44,7 +44,7 @@ public class SibaCLI
|
|||||||
File result;
|
File result;
|
||||||
result = SibaManager.backup(directoryToSave);
|
result = SibaManager.backup(directoryToSave);
|
||||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -60,7 +60,7 @@ public class SibaCLI
|
|||||||
File result;
|
File result;
|
||||||
result = SibaManager.backup(directoryToSave, targetDirectory);
|
result = SibaManager.backup(directoryToSave, targetDirectory);
|
||||||
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
System.out.println(BUNDLE.getString("confirmDialog.text") + result.getName()); //$NON-NLS-1$
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -86,7 +86,6 @@ public class SibaCLI
|
|||||||
{
|
{
|
||||||
System.out.println(yourFile + fileToCheck.getName() + bad);
|
System.out.println(yourFile + fileToCheck.getName() + bad);
|
||||||
}
|
}
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -21,6 +21,7 @@ package org.dclermonte.siba.gui;
|
|||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
|
import java.awt.Cursor;
|
||||||
import java.awt.FlowLayout;
|
import java.awt.FlowLayout;
|
||||||
import java.awt.Font;
|
import java.awt.Font;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
@ -49,15 +50,18 @@ public class AboutDialog extends JDialog
|
|||||||
*/
|
*/
|
||||||
public AboutDialog()
|
public AboutDialog()
|
||||||
{
|
{
|
||||||
getContentPane().setBackground(new Color(154, 205, 50));
|
setBackground(Color.GREEN);
|
||||||
|
getContentPane().setBackground(Color.GREEN);
|
||||||
setBounds(100, 100, 450, 300);
|
setBounds(100, 100, 450, 300);
|
||||||
getContentPane().setLayout(new BorderLayout());
|
getContentPane().setLayout(new BorderLayout());
|
||||||
{
|
{
|
||||||
JPanel buttonPane = new JPanel();
|
JPanel buttonPane = new JPanel();
|
||||||
|
buttonPane.setBackground(Color.GREEN);
|
||||||
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
|
||||||
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
getContentPane().add(buttonPane, BorderLayout.SOUTH);
|
||||||
{
|
{
|
||||||
JButton okButton = new JButton("OK");
|
JButton okButton = new JButton("OK");
|
||||||
|
okButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
okButton.addActionListener(new ActionListener()
|
okButton.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -74,11 +78,11 @@ public class AboutDialog extends JDialog
|
|||||||
}
|
}
|
||||||
|
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
panel.setBackground(new Color(0, 255, 255));
|
panel.setBackground(Color.GREEN);
|
||||||
getContentPane().add(panel, BorderLayout.CENTER);
|
getContentPane().add(panel, BorderLayout.CENTER);
|
||||||
|
|
||||||
JTextPane txtpnSimpleBackupDveloppeur = new JTextPane();
|
JTextPane txtpnSimpleBackupDveloppeur = new JTextPane();
|
||||||
txtpnSimpleBackupDveloppeur.setBackground(new Color(0, 255, 255));
|
txtpnSimpleBackupDveloppeur.setBackground(Color.GREEN);
|
||||||
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
|
txtpnSimpleBackupDveloppeur.setFont(new Font("Dialog", Font.BOLD, 14));
|
||||||
txtpnSimpleBackupDveloppeur.setText(
|
txtpnSimpleBackupDveloppeur.setText(
|
||||||
"Simple Backup\n\nDéveloppeur Christian Pierre Momon et Didier Clermonté\n\nLicence GNU Affero General Public License 2016");
|
"Simple Backup\n\nDéveloppeur Christian Pierre Momon et Didier Clermonté\n\nLicence GNU Affero General Public License 2016");
|
||||||
|
@ -106,11 +106,11 @@ public class BackupPanel extends JPanel
|
|||||||
public void actionPerformed(final ActionEvent e)
|
public void actionPerformed(final ActionEvent e)
|
||||||
{
|
{
|
||||||
File file = SourceDirectorySelector.showSelectorDialog(null, null);
|
File file = SourceDirectorySelector.showSelectorDialog(null, null);
|
||||||
if (file == null)
|
if (!(file == null))
|
||||||
{
|
{
|
||||||
return;
|
BackupPanel.this.textField.setText(file.getPath());
|
||||||
}
|
}
|
||||||
BackupPanel.this.textField.setText(file.getPath());
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
panel.add(btnNewButton, "6, 2");
|
panel.add(btnNewButton, "6, 2");
|
||||||
@ -133,11 +133,10 @@ public class BackupPanel extends JPanel
|
|||||||
{
|
{
|
||||||
|
|
||||||
File file = TargetDirectorySelector.showSelectorDialog(null, null);
|
File file = TargetDirectorySelector.showSelectorDialog(null, null);
|
||||||
if (file == null)
|
if (!(file == null))
|
||||||
{
|
{
|
||||||
return;
|
BackupPanel.this.textField_1.setText(file.getPath());
|
||||||
}
|
}
|
||||||
BackupPanel.this.textField_1.setText(file.getPath());
|
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -30,6 +30,7 @@ import java.awt.Point;
|
|||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.ResourceBundle;
|
import java.util.ResourceBundle;
|
||||||
@ -40,15 +41,17 @@ import javax.swing.JMenuBar;
|
|||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JSeparator;
|
||||||
import javax.swing.JTabbedPane;
|
import javax.swing.JTabbedPane;
|
||||||
import javax.swing.SwingConstants;
|
import javax.swing.SwingConstants;
|
||||||
import javax.swing.UIManager;
|
import javax.swing.UIManager;
|
||||||
import javax.swing.UnsupportedLookAndFeelException;
|
import javax.swing.UnsupportedLookAndFeelException;
|
||||||
|
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.dclermonte.siba.Siba;
|
|
||||||
import org.dclermonte.siba.SibaException;
|
import org.dclermonte.siba.SibaException;
|
||||||
import org.dclermonte.siba.gui.utils.GUIToolBox;
|
import org.dclermonte.siba.gui.utils.GUIToolBox;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The main class for GUI (Graphical User Interface )
|
* The main class for GUI (Graphical User Interface )
|
||||||
@ -59,7 +62,7 @@ import org.dclermonte.siba.gui.utils.GUIToolBox;
|
|||||||
public class SibaGUI
|
public class SibaGUI
|
||||||
{
|
{
|
||||||
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
private static final ResourceBundle BUNDLE = ResourceBundle.getBundle("org.dclermonte.siba.gui.messages"); //$NON-NLS-1$
|
||||||
|
public static final Logger logger = LoggerFactory.getLogger(SibaGUI.class);
|
||||||
/**
|
/**
|
||||||
* Launch the application.
|
* Launch the application.
|
||||||
*/
|
*/
|
||||||
@ -158,9 +161,10 @@ public class SibaGUI
|
|||||||
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/Cat-Box-32x32.png")));
|
.getImage(SibaGUI.class.getResource("/org/dclermonte/siba/gui/Cat-Box-32x32.png")));
|
||||||
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
this.frmSimpleBackup.getContentPane().setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
|
||||||
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
|
this.frmSimpleBackup.setMinimumSize(new Dimension(600, 400));
|
||||||
this.frmSimpleBackup.getContentPane().setBackground(new Color(173, 255, 47));
|
this.frmSimpleBackup.getContentPane().setBackground(Color.GREEN);
|
||||||
|
|
||||||
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
|
||||||
|
tabbedPane.setBackground(Color.GREEN);
|
||||||
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
tabbedPane.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
this.frmSimpleBackup.getContentPane().add(tabbedPane, BorderLayout.CENTER);
|
||||||
|
|
||||||
@ -182,14 +186,19 @@ public class SibaGUI
|
|||||||
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
this.frmSimpleBackup.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
|
||||||
JMenuBar menuBar = new JMenuBar();
|
JMenuBar menuBar = new JMenuBar();
|
||||||
menuBar.setBackground(new Color(152, 251, 152));
|
menuBar.setBackground(Color.GREEN);
|
||||||
this.frmSimpleBackup.setJMenuBar(menuBar);
|
this.frmSimpleBackup.setJMenuBar(menuBar);
|
||||||
|
|
||||||
JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text")); //$NON-NLS-1$
|
JMenu mnFile = new JMenu(BUNDLE.getString("SibaGUI.mnFile.text")); //$NON-NLS-1$
|
||||||
|
mnFile.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
|
mnFile.setBackground(Color.GREEN);
|
||||||
|
mnFile.setMnemonic('F');
|
||||||
mnFile.setForeground(Color.BLACK);
|
mnFile.setForeground(Color.BLACK);
|
||||||
menuBar.add(mnFile);
|
menuBar.add(mnFile);
|
||||||
|
|
||||||
JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text")); //$NON-NLS-1$
|
JMenuItem mntmBackup = new JMenuItem(BUNDLE.getString("SibaGUI.mntmBackup.text")); //$NON-NLS-1$
|
||||||
|
mntmBackup.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
|
mntmBackup.setBackground(Color.GREEN);
|
||||||
mntmBackup.addActionListener(new ActionListener()
|
mntmBackup.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -197,17 +206,19 @@ public class SibaGUI
|
|||||||
{
|
{
|
||||||
tabbedPane.setSelectedIndex(0);
|
tabbedPane.setSelectedIndex(0);
|
||||||
File file = SourceDirectorySelector.showSelectorDialog(null, null);
|
File file = SourceDirectorySelector.showSelectorDialog(null, null);
|
||||||
if (file == null)
|
if (!(file == null))
|
||||||
{
|
{
|
||||||
return;
|
BackupPanel.textField.setText(file.getPath());
|
||||||
}
|
}
|
||||||
BackupPanel.textField.setText(file.getPath());
|
|
||||||
// panel.setVisible(true);
|
// panel.setVisible(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
mnFile.add(mntmBackup);
|
mnFile.add(mntmBackup);
|
||||||
|
|
||||||
JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text")); //$NON-NLS-1$
|
JMenuItem mntmCheck = new JMenuItem(BUNDLE.getString("SibaGUI.mntmCheck.text")); //$NON-NLS-1$
|
||||||
|
mntmCheck.setBackground(Color.GREEN);
|
||||||
|
mntmCheck.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
mntmCheck.addActionListener(new ActionListener()
|
mntmCheck.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -231,6 +242,9 @@ public class SibaGUI
|
|||||||
mnFile.add(mntmCheck);
|
mnFile.add(mntmCheck);
|
||||||
|
|
||||||
JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text")); //$NON-NLS-1$
|
JMenuItem mntmQuit = new JMenuItem(BUNDLE.getString("SibaGUI.mntmQuit.text")); //$NON-NLS-1$
|
||||||
|
mntmQuit.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
|
mntmQuit.setBackground(Color.GREEN);
|
||||||
|
mntmQuit.setMnemonic(KeyEvent.VK_Q);
|
||||||
mntmQuit.addActionListener(new ActionListener()
|
mntmQuit.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@ -239,19 +253,24 @@ public class SibaGUI
|
|||||||
SibaGUI.this.frmSimpleBackup.dispose();
|
SibaGUI.this.frmSimpleBackup.dispose();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
JSeparator separator = new JSeparator();
|
||||||
|
mnFile.add(separator);
|
||||||
mnFile.add(mntmQuit);
|
mnFile.add(mntmQuit);
|
||||||
|
|
||||||
JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$
|
JMenu mnNewMenu = new JMenu(BUNDLE.getString("SibaGUI.mnNewMenu.text")); //$NON-NLS-1$
|
||||||
|
mnNewMenu.setMnemonic('H');
|
||||||
mnNewMenu.setLocation(new Point(500, 0));
|
mnNewMenu.setLocation(new Point(500, 0));
|
||||||
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
|
mnNewMenu.setHorizontalTextPosition(SwingConstants.RIGHT);
|
||||||
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
|
mnNewMenu.setHorizontalAlignment(SwingConstants.RIGHT);
|
||||||
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
mnNewMenu.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
mnNewMenu.setForeground(new Color(0, 0, 0));
|
mnNewMenu.setForeground(new Color(0, 0, 0));
|
||||||
mnNewMenu.setBackground(new Color(127, 255, 212));
|
mnNewMenu.setBackground(Color.GREEN);
|
||||||
mnNewMenu.setOpaque(true);
|
mnNewMenu.setOpaque(true);
|
||||||
menuBar.add(mnNewMenu);
|
menuBar.add(mnNewMenu);
|
||||||
|
|
||||||
JMenuItem mntmNewMenuItem_2 = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
|
JMenuItem mntmNewMenuItem_2 = new JMenuItem(BUNDLE.getString("SibaGUI.mntmNewMenuItem_2.text")); //$NON-NLS-1$
|
||||||
|
mntmNewMenuItem_2.setBackground(Color.GREEN);
|
||||||
mntmNewMenuItem_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
mntmNewMenuItem_2.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
|
||||||
mntmNewMenuItem_2.addActionListener(new ActionListener()
|
mntmNewMenuItem_2.addActionListener(new ActionListener()
|
||||||
{
|
{
|
||||||
@ -303,7 +322,7 @@ public class SibaGUI
|
|||||||
String dataMissing = sibaException.getMessage();
|
String dataMissing = sibaException.getMessage();
|
||||||
if (!(sibaException.getCause() == null))
|
if (!(sibaException.getCause() == null))
|
||||||
{
|
{
|
||||||
Siba.logger.info("SibaException chainée = " + sibaException.getCause().getMessage());
|
logger.info("SibaException chainée = " + sibaException.getCause().getMessage());
|
||||||
// dataMissing.concat(sibaException.getCause().getMessage());
|
// dataMissing.concat(sibaException.getCause().getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,8 +25,8 @@ CheckPanel.confirmDialogYourString.text=Your File
|
|||||||
CheckPanel.lblNewLabel.text=File to be Checked
|
CheckPanel.lblNewLabel.text=File to be Checked
|
||||||
SibaGUI.mnFile.text=File
|
SibaGUI.mnFile.text=File
|
||||||
SibaGUI.mnNewMenu.text=Help
|
SibaGUI.mnNewMenu.text=Help
|
||||||
SibaGUI.mntmBackup.text=Backup
|
SibaGUI.mntmBackup.text=Backup...
|
||||||
SibaGUI.mntmCheck.text=Check
|
SibaGUI.mntmCheck.text=Check...
|
||||||
SibaGUI.mntmNewMenuItem_1.text=End
|
SibaGUI.mntmNewMenuItem_1.text=End
|
||||||
SibaGUI.mntmNewMenuItem_2.text=About
|
SibaGUI.mntmNewMenuItem_2.text=About
|
||||||
SibaGUI.mntmQuit.text=Quit
|
SibaGUI.mntmQuit.text=Quit
|
||||||
|
@ -28,6 +28,6 @@ CheckPanel.confirmDialogBad.text = comporte des erreurs
|
|||||||
BackupPanel.dataMissing.text = Données incomplètes
|
BackupPanel.dataMissing.text = Données incomplètes
|
||||||
BackupPanel.TitleWarning.text = Attention
|
BackupPanel.TitleWarning.text = Attention
|
||||||
SibaGUI.mnFile.text=Fichier
|
SibaGUI.mnFile.text=Fichier
|
||||||
SibaGUI.mntmBackup.text=Sauvegarde
|
SibaGUI.mntmBackup.text=Sauvegarde...
|
||||||
SibaGUI.mntmQuit.text=Sortir
|
SibaGUI.mntmQuit.text=Quitter
|
||||||
SibaGUI.mntmCheck.text=Vérification
|
SibaGUI.mntmCheck.text=Vérification...
|
@ -20,6 +20,7 @@
|
|||||||
package org.dclermonte.siba.model;
|
package org.dclermonte.siba.model;
|
||||||
|
|
||||||
import java.io.BufferedOutputStream;
|
import java.io.BufferedOutputStream;
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@ -27,7 +28,6 @@ import java.io.FileReader;
|
|||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.security.MessageDigest;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
@ -78,6 +78,7 @@ public class SibaManager
|
|||||||
{
|
{
|
||||||
File result;
|
File result;
|
||||||
TarArchiveOutputStream out = null;
|
TarArchiveOutputStream out = null;
|
||||||
|
OutputStream gzipOutputStream = null;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -101,7 +102,7 @@ public class SibaManager
|
|||||||
String textDate = date.format(formatter);
|
String textDate = date.format(formatter);
|
||||||
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
|
String outputFileNameWithoutExtension = fileToSave.getName() + "-" + textDate;
|
||||||
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
|
result = new File(target + "/" + outputFileNameWithoutExtension + ".tgz");
|
||||||
OutputStream gzipOutputStream = new GzipCompressorOutputStream(
|
gzipOutputStream = new GzipCompressorOutputStream(
|
||||||
new BufferedOutputStream(new FileOutputStream(result)));
|
new BufferedOutputStream(new FileOutputStream(result)));
|
||||||
out = new TarArchiveOutputStream(gzipOutputStream);
|
out = new TarArchiveOutputStream(gzipOutputStream);
|
||||||
directoryToSave(fileToSave, out, pathLength);
|
directoryToSave(fileToSave, out, pathLength);
|
||||||
@ -121,6 +122,7 @@ public class SibaManager
|
|||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
IOUtils.closeQuietly(out);
|
IOUtils.closeQuietly(out);
|
||||||
|
IOUtils.closeQuietly(gzipOutputStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@ -140,9 +142,9 @@ public class SibaManager
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String md5String = loadMD5Sum(choosenFile);
|
String md5String = SibaUtils.loadMD5Sum(choosenFile);
|
||||||
File fileToCheck1 = loadFileToCheck(choosenFile);
|
File fileToCheck1 = loadFileToCheck(choosenFile);
|
||||||
if (StringUtils.equals(md5String, md5(fileToCheck1)))
|
if (StringUtils.equals(md5String, SibaUtils.md5(fileToCheck1)))
|
||||||
{
|
{
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
@ -224,7 +226,7 @@ public class SibaManager
|
|||||||
|
|
||||||
result = new File(destination);
|
result = new File(destination);
|
||||||
FileWriter fileWriter = new FileWriter(result);
|
FileWriter fileWriter = new FileWriter(result);
|
||||||
fileWriter.write(md5(directoryToSave));
|
fileWriter.write(SibaUtils.md5(directoryToSave));
|
||||||
String newLine = System.getProperty("line.separator");
|
String newLine = System.getProperty("line.separator");
|
||||||
fileWriter.append(" " + directoryToSave.getName() + newLine);
|
fileWriter.append(" " + directoryToSave.getName() + newLine);
|
||||||
fileWriter.close();
|
fileWriter.close();
|
||||||
@ -245,7 +247,8 @@ public class SibaManager
|
|||||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||||
{
|
{
|
||||||
FileReader fileReader = new FileReader(choosenFile);
|
FileReader fileReader = new FileReader(choosenFile);
|
||||||
|
BufferedReader bufferedReader = new BufferedReader(fileReader);
|
||||||
|
String line = bufferedReader.readLine();
|
||||||
char[] fileToCheck = new char[(int) (choosenFile.length()) - 32];
|
char[] fileToCheck = new char[(int) (choosenFile.length()) - 32];
|
||||||
fileReader.read();
|
fileReader.read();
|
||||||
fileReader.skip(32);
|
fileReader.skip(32);
|
||||||
@ -271,76 +274,4 @@ public class SibaManager
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* @param choosenFile
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
|
||||||
public static String loadMD5Sum(final File choosenFile) throws IOException
|
|
||||||
{
|
|
||||||
String result = "";
|
|
||||||
|
|
||||||
if (choosenFile.exists() && (choosenFile.length() > 32))
|
|
||||||
{
|
|
||||||
FileReader fileReader = new FileReader(choosenFile);
|
|
||||||
char[] md5 = new char[32];
|
|
||||||
byte[] md5byte = new byte[32];
|
|
||||||
for (int index = 0; index < 32; index++)
|
|
||||||
{
|
|
||||||
md5[index] = (char) fileReader.read();
|
|
||||||
md5byte[index] = (byte) md5[index];
|
|
||||||
result = result + md5[index];
|
|
||||||
}
|
|
||||||
fileReader.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This method calculate the MD5 itself.
|
|
||||||
*
|
|
||||||
* @param input
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
* @throws NoSuchAlgorithmException
|
|
||||||
*/
|
|
||||||
public static String md5(final File input) throws IOException, NoSuchAlgorithmException
|
|
||||||
{
|
|
||||||
String result;
|
|
||||||
StringBuilder hashString = new StringBuilder();
|
|
||||||
|
|
||||||
byte[] byteInput = new byte[(int) input.length()];
|
|
||||||
FileInputStream fileInputStream = new FileInputStream(input);
|
|
||||||
for (int index1 = 0; index1 < input.length(); index1++)
|
|
||||||
{
|
|
||||||
byteInput[index1] = (byte) fileInputStream.read();
|
|
||||||
}
|
|
||||||
byte[] hash = null;
|
|
||||||
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
|
||||||
hash = messageDigest.digest(byteInput);
|
|
||||||
|
|
||||||
for (int index = 0; index < hash.length; index++)
|
|
||||||
{
|
|
||||||
String hex = Integer.toHexString(hash[index]);
|
|
||||||
if (hex.length() == 1)
|
|
||||||
{
|
|
||||||
hashString.append('0');
|
|
||||||
hashString.append(hex.charAt(hex.length() - 1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
hashString.append(hex.substring(hex.length() - 2));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fileInputStream.close();
|
|
||||||
|
|
||||||
result = hashString.toString();
|
|
||||||
//
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
92
src/org/dclermonte/siba/model/SibaUtils.java
Normal file
92
src/org/dclermonte/siba/model/SibaUtils.java
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
package org.dclermonte.siba.model;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.security.MessageDigest;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
|
import org.apache.commons.compress.utils.IOUtils;
|
||||||
|
|
||||||
|
public class SibaUtils
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param choosenFile
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
public static String loadMD5Sum(final File choosenFile) throws IOException
|
||||||
|
{
|
||||||
|
String result = "";
|
||||||
|
|
||||||
|
if (choosenFile.exists() && (choosenFile.length() > 32))
|
||||||
|
{
|
||||||
|
FileReader fileReader = new FileReader(choosenFile);
|
||||||
|
char[] md5 = new char[32];
|
||||||
|
byte[] md5byte = new byte[32];
|
||||||
|
for (int index = 0; index < 32; index++)
|
||||||
|
{
|
||||||
|
md5[index] = (char) fileReader.read();
|
||||||
|
md5byte[index] = (byte) md5[index];
|
||||||
|
result = result + md5[index];
|
||||||
|
}
|
||||||
|
fileReader.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method calculate the MD5 itself.
|
||||||
|
*
|
||||||
|
* @param input
|
||||||
|
* @return
|
||||||
|
* @throws IOException
|
||||||
|
* @throws NoSuchAlgorithmException
|
||||||
|
*/
|
||||||
|
public static String md5(final File input) throws IOException, NoSuchAlgorithmException
|
||||||
|
{
|
||||||
|
String result;
|
||||||
|
StringBuilder hashString = new StringBuilder();
|
||||||
|
FileInputStream fileInputStream = null;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
byte[] byteInput = new byte[(int) input.length()];
|
||||||
|
fileInputStream = new FileInputStream(input);
|
||||||
|
for (int index1 = 0; index1 < input.length(); index1++)
|
||||||
|
{
|
||||||
|
byteInput[index1] = (byte) fileInputStream.read();
|
||||||
|
}
|
||||||
|
byte[] hash = null;
|
||||||
|
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
|
||||||
|
hash = messageDigest.digest(byteInput);
|
||||||
|
|
||||||
|
for (int index = 0; index < hash.length; index++)
|
||||||
|
{
|
||||||
|
String hex = Integer.toHexString(hash[index]);
|
||||||
|
if (hex.length() == 1)
|
||||||
|
{
|
||||||
|
hashString.append('0');
|
||||||
|
hashString.append(hex.charAt(hex.length() - 1));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hashString.append(hex.substring(hex.length() - 2));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileInputStream.close();
|
||||||
|
|
||||||
|
result = hashString.toString();
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
IOUtils.closeQuietly(fileInputStream);
|
||||||
|
}
|
||||||
|
//
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user