خرید بک لینک

Vote count: -1

need help to optimize this codeneed help to optimize this codeneed help to optimize this codeneed help to optimize this codeneed help to optimize this codeneed help to optimize this codeneed help to optimize this codeneed help to optimize this code import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.ArrayList;

public class Utilities {
          public static boolean checkBTName(String btName) {
                    if (btName.startsWith("IS") || btName.startsWith("MS"))
                              retu false;
                    else
                              retu true;
          }

          public static boolean checkServiceName(String serviceName) {
                    if (serviceName.startsWith("IS"))
                              retu true;
                    else
                              retu false;
          }

          public static boolean checkMsgSetName(String msgSetName) {
                    if (msgSetName.startsWith("MS"))
                              retu true;
                    else
                              retu false;
          }

          public static void copyOrReplaceFile(String sourceLocation,
                              String destination, String FileName) {
                    File sourceFile = new File(sourceLocation);
                    File destinationFile = new File(destination);
                    /* if file exists we will check the last modified timestamp */
                    if (destinationFile.exists()) {
                              long sourceLastModified = sourceFile
                                                  .lastModified();
                              long destinationLastModified = destinationFile
                                                  .lastModified();
                              if (destinationLastModified < sourceLastModified) {
                                        try {
                                                  FileInputStream fis = new FileInputStream(
                                                                      sourceFile);
                                                  FileOutputStream fos = new FileOutputStream(
                                                                      destinationFile);
                                                  int bytes;
                                                  while ((bytes = fis.read()) != -1) {
                                                            fos.write(bytes);
                                                  }
                                                  fos.close();
                                                  fis.close();
                                                  System.out.println("file replaced");
                                        } catch (Exception e) {

                                        }
                              }
                    } else {
                              try {
                                        FileInputStream fis = new FileInputStream(
                                                            sourceFile);
                                        FileOutputStream fos = new FileOutputStream(
                                                            destinationFile);
                                        int bytes;
                                        while ((bytes = fis.read()) != -1) {
                                                  fos.write(bytes);
                                        }
                                        fos.close();
                                        fis.close();
                                        System.out.println("file replaced");
                              } catch (Exception e) {
                                        e.printStackTrace();
                              }
                    }

          }

          public static void copyFolder(File source, File destination) {
                    if (source.isDirectory()) {
                              if (!destination.exists()) {
                                        destination.mkdirs();
                              }

                              String files[] = source.list();

                              for (String file : files) {
                                        File srcFile = new File(source, file);
                                        File destFile = new File(destination,
                                                            file);

                                        copyFolder(srcFile, destFile);
                              }
                    } else {
                              InputStream in = null;
                              OutputStream out = null;

                              try {
                                        in = new FileInputStream(source);
                                        out = new FileOutputStream(destination);

                                        byte[] buffer = new byte[1024];

                                        int length;
                                        while ((length = in.read(buffer)) > 0) {
                                                  out.write(buffer, 0, length);
                                        }
                              } catch (Exception e) {
                                        try {
                                                  in.close();
                                                  out.close();
                                        } catch (IOException e1) {
                                                  e1.printStackTrace();
                                        }
                              }
                    }
          }

          public static void copySource(String RTCWorkspace,
                              String toolkitWorkspacePath,
                              ArrayList<String> btSelected,
                              ArrayList<String> msgSetSelected,
                              ArrayList<String> serviceSelected) {
                    /* copying BT's first */
                    for (String BTFolderName : btSelected) {
                              File sourceFolder = new File(toolkitWorkspacePath
                                                  + "\" + BTFolderName);
                              File destinationFolder = new File(RTCWorkspace
                                                  + "\source\bustrans\"
                                                  + BTFolderName);
                              copyFolder(sourceFolder, destinationFolder);
                    }
                    for (String serviceFolderName : serviceSelected) {
                              File sourceFolder = new File(toolkitWorkspacePath
                                                  + "\" + serviceFolderName);
                              File destinationFolder = new File(RTCWorkspace
                                                  + "\source\services\"
                                                  + serviceFolderName);
                              copyFolder(sourceFolder, destinationFolder);
                    }
                    for (String msgSetFolderName : msgSetSelected) {
                              File sourceFolder = new File(toolkitWorkspacePath
                                                  + "\" + msgSetFolderName);
                              File destinationFolder = new File(RTCWorkspace
                                                  + "\source\msgsets\"
                                                  + msgSetFolderName);
                              copyFolder(sourceFolder, destinationFolder);
                    }

                    System.out.println("Source Copied");
          }
}

asked 3 mins ago

- - , .

برچسب: نویسنده: استخدام کار تاريخ: يکشنبه 16 اسفند 1394 ساعت: 22:29

صفحه بندی