Search This Blog

Showing posts with label copy. Show all posts
Showing posts with label copy. Show all posts

Thursday, June 1, 2023

Linux Ubuntu - SSH command to copy server to local or vice versa

 Copy file to Server to Local

    scp -P <port> <localfile path> <server user>@ip:<remote user home path>

    ex: > scp -P 22 mq/target/test.jar drvijay@192.2.2.2:/home/drvijay


Connect server : 

        ssh -p <port> <server user>@<IP>
        ssh -p 22 drvijay@182.2.2.2

Copy file from Server to Local
 





Note: ssh -p <port> small case for port option
          scp -P <port> upper -P for port specify.




Monday, April 24, 2023

Java Sample - Copy any object into any object including sub object fields generic

 Steps 1:

Source

Person.java(list address)

Address.java(User.java)


public class Person implements Serializable

{

private String firstName;

private String lastName;

private int age;

private List <AddressaddressList;

}

public class Address implements Serializable

{

private int id;

private String address1;

private String address2;

private String city;

private String state;

private String country;

private String pincode;

private String contactNumber;

private String email;

private User user;

}




Target

PersonDTO.java (list addressDTO)

AddressDTO.java (User.java)

public class PersonDTO implements Serializable

{

private String firstName;

private int age;

private String lastName;

private List <AddressDTO> addressList;

}

public class AddressDTO implements Serializable

{

private int id;

private String address1;

private String address2;

private String city;

private String state;

private String country;

private String pincode;

private String contactNumber;

private String email;

private User user;

}


Step 2: Sample java class

package com.drvijay;

import java.lang.reflect.Field;

import java.lang.reflect.Modifier;

import java.util.ArrayList;

import java.util.Arrays;

import java.util.HashMap;

import java.util.List;

import org.apache.commons.lang3.RandomStringUtils;

import com.product.base.utils.ObjectUtils;

import com.product.base.utils.ProductConstants;

/**

* @author drvijay

* @date Apr-20-2023 10:30 AM

*/

@SuppressWarnings ( "unused" )

public class UtilHelper

{

private static final long serialVersionUID = 1L;

public static void copy ( Object source, Object target ) throws IllegalArgumentException, IllegalAccessException

{

Class <?> sourceClass = source.getClass ();

Class <?> targetClass = target.getClass ();

Field [] sourceFields = sourceClass.getDeclaredFields ();

Field [] targetFields = targetClass.getDeclaredFields ();

for ( Field sourceField : sourceFields )

{

for ( Field targetField : targetFields )

{

// If the source and target fields have the same name and type

if ( sourceField.getName ().equals ( targetField.getName () ) && sourceField.getType ().equals ( targetField.getType () ) )

{

// Make the source and target field accessible

sourceField.setAccessible ( true );

targetField.setAccessible ( true );

// Copy the value from the source field to the target field

targetField.set ( target, sourceField.get ( source ) );

// Stop looping through the target fields

break;

}

}

}

}

public static void main ( String [] args ) throws Exception

{

// Create a source object

Person sourcePerson = new Person ();

sourcePerson.setFirstName ( "vijay" );

sourcePerson.setLastName ( "kumar" );

sourcePerson.setAge ( 30 );

User u = new User ();

u.setUA ( "ua" );

u.setUB ( "ub" );

List<Address> aList = new ArrayList();

Address address = new Address ();

address.setAddress1 ( "add 1" );

address.setAddress2 ( "add 2" );

address.setPincode ( "54534" );

address.setUser ( u );

aList.add ( address );

address = new Address ();

address.setAddress1 ( "add 11" );

address.setAddress2 ( "add 22" );

address.setPincode ( "545341" );

aList.add ( address );

sourcePerson.setAddressList ( aList );

// Create a target object with similar properties

PersonDTO targetPersonDTO = new PersonDTO ();

// Copy the properties from the source object to the target object

UtilHelper.copy ( sourcePerson, targetPersonDTO );

// Print the values of the target object

System.out.println ( targetPersonDTO.getFirstName () );

System.out.println ( targetPersonDTO.getAge () );

System.out.println ( sourcePerson.toString () );

System.out.println ( targetPersonDTO.toString () );

System.out.println ( targetPersonDTO.getAddressList ().toString () );

}

}



Output


vijay

30

Person(firstName=vijay, lastName=kumar, age=30, addressList=[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)])

PersonDTO(firstName=vijay, age=30, lastName=kumar, addressList=[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)])

[Address(id=0, address1=add 1, address2=add 2, city=null, state=null, country=null, pincode=54534, contactNumber=null, email=null, user=User(uA=ua, uB=ub)), Address(id=0, address1=add 11, address2=add 22, city=null, state=null, country=null, pincode=545341, contactNumber=null, email=null, user=null)]


Friday, July 23, 2021

How to install Gnome Extensions

 Extract the downloaded file. Copy the folder to ~/.local/share/gnome-shell/extensions directory. Go to your Home directory and press Crl+H to show hidden folders. Locate .local folder here and from there, you can find your path till extensions directory. 

Once you have the files copied in the correct directory, go inside it and open metadata.json file. Look for the value of uuid. 

Make sure that the name of the extension’s folder is same as the value of uuid in the metadata.json file. If not, rename the directory to the value of this uuid.

Manually install GNOME Shell extension
Name of extension folder should be the same as uuid

Almost there! Now restart GNOME Shell. Press Alt+F2 and enter r to restart GNOME Shell.

Restart GNOME Shell
Restart GNOME Shell

Restart GNOME Tweaks tool as well. You should see the manually installed GNOME extension in the Tweak tool now. You can configure or enable the newly installed extension here.

And that’s all you need to know about installing GNOME Shell Extensions.

Remove GNOME Shell Extensions

It is totally understandable that you might want to remove an installed GNOME Shell Extension.

If you installed it via a web browser, you can go to the installed extensions section on GNOME website and remove it from there (as shown in an earlier picture).

If you installed it manually, you can remove it by deleting the extension files from ~/.local/share/gnome-shell/extensions directory.

Tuesday, March 24, 2020

Java : Static method to get classes/Resources folder and copy from inside zip to outter



URL url = MethodHandles.lookup().lookupClass().getResource ( "text.json" );
FileUtils.copyURLToFile(url,  new File ( "D:/text.json" ) );

Friday, August 16, 2019

Hit Counter


View My Stats