Drop Down

Showing posts with label bupa. Show all posts
Showing posts with label bupa. Show all posts

Sunday, October 6, 2019

Send Free SMS using Java code

package freesms;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;

public class SendSMS
{

public static void main(String[] args)
{
try {
// Construct data
String apiKey = "apikey=" + "2D5i+ah7Dtw-6Ggu4kukZUJrnHddMJLXjNvFGstF3A"; // only 10 credits left
String message = "&message=" + "This is your message";
String sender = "&sender=" + "TXTLCL"; //not to be changed
String numbers = "&numbers=" + "8744973456";

// Send data
HttpURLConnection conn = (HttpURLConnection) new URL("https://api.textlocal.in/send/?").openConnection();
String data = apiKey + numbers + message + sender;
conn.setDoOutput(true);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Length", Integer.toString(data.length()));
conn.getOutputStream().write(data.getBytes("UTF-8"));
final BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
final StringBuffer stringBuffer = new StringBuffer();
String line;
while ((line = rd.readLine()) != null)
{
stringBuffer.append(line);
System.out.println(">>> "+stringBuffer);

}
rd.close();

//return stringBuffer.toString();

  }
catch (Exception e)
{
System.out.println("Error SMS " + e);
//return "Error " + e;
}

}

}
==================================================
---------
 NOTE
---------
Website :  https://control.textlocal.in/settings/apikeys/
id: amitin2015@gmail.com
P/W: S****g***19
===================================================

Saturday, September 21, 2019

Code to Move log dump to another location

package com.amit.model;

import java.io.File;
import java.io.FileInputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;

public class ScanToMoveFolder
{
static File source1 = null;
static File dest1 = null;
public static void main(String[] args)
{
//***************************READING PROPERTIES FILE*****************
try
{
  FileInputStream ip = new FileInputStream("config.properties");
  Properties prop = new Properties();
  prop.load(ip);
  source1 = new File(prop.getProperty("fromPath_1"));
  dest1 = new File(prop.getProperty("toPath_1"));
 
  ProcessData p1 = new ProcessData();
  Thread t1 = new Thread(p1);
  t1.start();  
 
}
catch(Exception e)
{
e.printStackTrace();
}

}


}



=====================================================================

package com.amit.model;

import java.io.File;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.commons.io.FileUtils;

public class ProcessData implements Runnable
{
private boolean keepRunning = true;
private File source1 = ScanToMoveFolder.source1;
private File dest1 = ScanToMoveFolder.dest1;
ProcessData pro;
public String timestamp = null;
public void stop()
{
keepRunning = false;
}
private  String gettime()
{
DateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy");
Date date = new Date();
return dateFormat.format(date);
}
private  String getDatetime()
{
DateFormat dateFormat = new SimpleDateFormat("dd-M-yyyy hh:mm:ss");
Date date = new Date();
return dateFormat.format(date);
}

public void run()
{
while(keepRunning)
{
try
{
timestamp = gettime();
System.out.println("TIMESTAMP::>> "+timestamp);
copyFolder(source1,dest1);
deleteFiles(source1);
System.out.println("*********************************************************");
System.out.println("************UTILITY IS SLEEPING FOR  24 HR***************");
System.out.println("*********************************************************");
System.out.println("*****Utility started to sleep at :"+getDatetime()+"******");
System.out.println("*********************************************************");
Thread.sleep(1000*60*60*24);
}
catch(Exception e)
{
e.printStackTrace();
}
}

}

private void copyFolder(File sourceFolder, File destinationFolder)
{
try
{
System.out.println("source folder "+sourceFolder);
System.out.println("destination folder "+destinationFolder);
if(sourceFolder.isDirectory())
{
if(!destinationFolder.exists())
{
destinationFolder.mkdir();
System.out.println("Directory Created :: "+destinationFolder);
}
String path = check_if_leaf_directory(sourceFolder,destinationFolder); //$$$$$$$$$$$$$$$$$$$$$$$$
System.out.println("Path::"+path);
File path_file = new File(path);
destinationFolder = path_file;
String files[] = sourceFolder.list();
for(String file : files)
{
//boolean dir_flag = false;
File srcFile = new File(sourceFolder,file);
File destFile = new File(destinationFolder,file);
copyFolder(srcFile,destFile);
}
}
else
{
//Files.copy(sourceFolder.toPath(), destinationFolder.toPath(), StandardCopyOption.REPLACE_EXISTING); //---> for java 7 and above
FileUtils.copyFile(sourceFolder, destinationFolder);  //----> for java 1.6 and lower
System.out.println("File copied :: "+destinationFolder);
}

}
catch(Exception e)
{
e.printStackTrace();
}

}

private String check_if_leaf_directory(File dir, File destination)
{
String path = destination.toString();
System.out.println("path********* "+path);
try
{
File[] files = dir.listFiles();
for(File file : files)
{
if(!file.isDirectory())
{
String destination_appended_path_str = (destination + File.separator +timestamp);
File destination_appended_path_file = new File(destination_appended_path_str);
destination_appended_path_file.mkdir();

path = destination_appended_path_file.toString();
System.out.println("<<path>>"+path);
}
else
{

}

}

}
catch(Exception e)
{
e.printStackTrace();
}
return path;
}
private void deleteFiles(File dir)
{
try
{
  File[] files = dir.listFiles();
  for(File file1 : files)
  {
  if(file1.isDirectory())
  {
  System.out.println("Directory: "+file1.getCanonicalPath());
  deleteFiles(file1);
  }
  else
  {
  file1.delete();
  System.out.println("inside else..."+file1.getAbsolutePath());
  }
 
  }
}
catch(Exception e)
{
e.printStackTrace();
}

}

}



============================config.properties==========================

fromPath_1 = D:\\\\work\\TestEnv\\source
toPath_1 = D:\\\\work\\TestEnv\\destination







Java 8 Notes Pics