Skip to content

Instantly share code, notes, and snippets.

File input = new File("/file/to/path");
File destination = new File("/file/to");
Archiver archiver = ArchiverFactory.createArchiver(ArchiveFormat.ZIP);
((Archiver) archiver).extract(input,destination);
/* unzip file
String zipFile = "/file/to/path";
File destinationDir = new File("/file/to/);
java.util.zip.ZipFile zipFile = new ZipFilezipFile
try{
Enumeration<? extends ZipEntry> entries = zipFile.entries();
while (entries.hasMoreElements()){
ZipEntry entry = entries.nextElement();
File entryDestination = new File(destinationDir);
public void zipDirectory(File dir, String zipDirName){
try{
populateFilesList(dir);
FileOutputStream fos = new FileOutputStream(zipDirName);
ZipOutputStream zos = new ZipOutputStream(fos);
for(String filePath : filesListInDir){
System.out.println("zipping " + filePath);
ZipEntry ze = new ZipEntry(filePath.substring(dir.getAbsolutePath().length() + 1, filePath.length()));
zos.putNextEntry(ze);
FileInputStream fis = new FileInputStream(filePath);
public void tarDirectory(File dir, TarOutputStream zos, String lPath) {
try {
for (File filePath : dir.listFiles()) {
System.out.println("Tarring " + filePath);
TarEntry entry = new TarEntry(filePath,filePath.getAbsolutePath().substring(lPath.length()));
zos.putNextEntry(entry);
if(filePath.isDirectory()){
tarDirectory(filePath,zos,lPath);
}
else if (filePath.isFile()){
//Digital sign
public static void Signature(String zipDirName, String lPath) throws NoSuchAlgorithmException, InvalidKeyException, IOException, SignatureException, NoSuchProviderException, InvalidKeySpecException {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("DSA","SUN");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
PublicKey publicKey = keyPair.getPublic();
Signature dsa = Signature.getInstance("SHA1withDSA", "SUN");
public static void Encrypto() throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, NoSuchPaddingException, InvalidKeyException, BadPaddingException, IllegalBlockSizeException, NoSuchProviderException {
KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA");
keyPairGenerator.initialize(1024);
KeyPair keyPair = keyPairGenerator.generateKeyPair();
PrivateKey privateKey = keyPair.getPrivate();
try (FileInputStream fis = new FileInputStream("File.txt");
FileOutputStream fos = new FileOutputStream("FileEncrypt.txt")) {
public static void Encrypt() throws NoSuchPaddingException, NoSuchAlgorithmException, InvalidKeyException, IOException {
try (FileInputStream fis = new FileInputStream("File.zip");
FileOutputStream fos = new FileOutputStream("EncryptFile.zip")) {
byte k[] = "NiTh5252".getBytes();
SecretKeySpec key = new SecretKeySpec(k, "DES");
Cipher enc = Cipher.getInstance("DES");
enc.init(Cipher.ENCRYPT_MODE, key);
CipherOutputStream cos = new CipherOutputStream(fos, enc);
public void Banka()
{
string sql = @"SELECT [Hesap kodu]
,[Hesap Adı]
FROM ...";
using (SqlConnection con = new SqlConnection(SessionHelper.ConnectionString))
{
if (con.State != System.Data.ConnectionState.Open)
con.Open();
public void BankAccount_()
{
string sql = @"SELECT [Hesap kodu]
,[Hesap Adı]
FROM ...";
using (SqlConnection con = new SqlConnection(SessionHelper.ConnectionString))
{
if (con.State != System.Data.ConnectionState.Open)
con.Open();
[Action(Caption = "Add Company")]
public void Company_Transfer()
{
StaticDefinitions sdMuhasebeKodu = Session.FindObject<StaticDefinitions>(CriteriaOperator.Parse("Key == 'Acc_Company_Account'"));
if (sdMuhasebeKodu == null)
throw new UserFriendlyException("Muhasebe kodu static tanım bulunamadı");
string sql = @"SELECT [Hesap kodu]
,[Hesap Adı]
FROM ...]";