Translate

30 Temmuz 2021 Cuma

java 8 splitting bytes into chunks

 public List<byte[]> getFileChunks(byte[] mainFile) {

int sizeMB = 1 * 1024 * 1024; List<byte[]> chunks = new ArrayList<>(); for (int i = 0; i < mainFile.length; ) { byte[] chunk = new byte[Math.min(sizeMB, mainFile.length - i)]; for (int j = 0; j < chunk.length; j++, i++) { chunk[j] = mainFile[i]; } chunks.add(chunk); } return chunks; }

or if you want a functional solution, then try this:

public List<byte[]> getFileChunks(byte[] mainFile) { final int sizeMB = 1 * 1024 * 1024; return IntStream.iterate(0, i -> i + sizeMB) .limit((mainFile.length + sizeMB - 1) / sizeMB) .mapToObj(i -> Arrays.copyOfRange(mainFile, i, Math.min(i + sizeMB, mainFile.length))) .collect(Collectors.toList()); }




or


public static byte[][] divideArray(byte[] source, int chunksize) {
     
            byte[][] ret = new byte[(int)Math.ceil(source.length / (double)chunksize)][chunksize];
     
            int start = 0;
     
            for(int i = 0; i < ret.length; i++) {
                ret[i] = Arrays.copyOfRange(source,start, start + chunksize);
                start += chunksize ;
            }
     
            return ret;

    } 

16 Mayıs 2021 Pazar

java.lang.Exception: exception just for purpose of providing stack trace

 JDBC transaction marked for rollback-only (exception provided for stack trace)


java.lang.Exception: exception just for purpose of providing stack trace


Check your Entity mine was becauseof enum 


@Data
@NoArgsConstructor
@Entity
@Table
public class UserTokenModel {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
// @NotBlank
private String userEmail;
private String token;
private boolean enabled;

@NotBlank
@Enumerated(EnumType.STRING)
private EmailType emailType;

13 Mayıs 2021 Perşembe

Test class should have exactly one public zero-argument constructor

 Make sure you have initialized your Test class correctly


befor 

private final LoadBalanceService loadBalanceService;

public LoadBalanceServiceTest(LoadBalanceService loadBalanceService) {
this.loadBalanceService = loadBalanceService;
}

AFter fix
private final LoadBalanceService loadBalanceService = new LoadBalanceService();

22 Şubat 2021 Pazartesi

replacePattern


https://regexr.com/

<a href="https://deneme/">https://deneme/</a>




var replacePattern = /(\<a([^>]*?)(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
resp.eulaTextUrl = resp.eulaTextUrl.replace(replacePattern'$1?openInExternalBrowser=true" target="_blank');

18 Haziran 2020 Perşembe

Take href value with regex


https://regexr.com/

<a href="https://deneme/">https://deneme/</a>

Take href and change



var replacePattern = /(\<a([^>]*?)(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
resp.eulaTextUrl = resp.eulaTextUrl.replace(replacePattern'$1?openInExternalBrowser=true" target="_blank');




 var httpPattern = /(\<a([^>]*?)(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
      resp.eulaTextUrl = resp.eulaTextUrl.replace(httpPattern'$1?openInExternalBrowser=true" target="_blank');
      var mailPattern = /(\<a([^>]*?)(mailto):[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
      resp.eulaTextUrl = resp.eulaTextUrl.replace(mailPattern'$1?openInExternalBrowser=true" data-rel="external');

https://stackoverflow.com/questions/37684/how-to-replace-plain-urls-with-links/21925491


function linkify(inputText) {
    var replacedText, replacePattern1, replacePattern2, replacePattern3;

    //URLs starting with http://, https://, or ftp://
    replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
    replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');

    //URLs starting with "www." (without // before it, or it'd re-link the ones done above).
    replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
    replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');

    //Change email addresses to mailto:: links.
    replacePattern3 = /(([a-zA-Z0-9\-\_\.])+@[a-zA-Z\_]+?(\.[a-zA-Z]{2,6})+)/gim;
    replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');

    return replacedText;
}

15 Haziran 2020 Pazartesi



private void requestMarshall(CreateOrderRequest request){
   try {
      JAXBContext jaxbContext = JAXBContext.newInstance(CreateOrderRequest.class);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      StringWriter stringWriter = new StringWriter();
      jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
      QName qName = new QName("http://deneme//EmployeeTypes", "CreateOrderRequest");
      JAXBElement<CreateOrderRequest> root = new JAXBElement<CreateOrderRequest>(qName, CreateOrderRequest.class, request);
      jaxbMarshaller.marshal(root, stringWriter);
      String result = stringWriter.toString();
      getLogger().warn("Create order request XML: {}" ,result);
   }catch (JAXBException jb){
      getLogger().error("Create order request XML marshall error: {}" ,jb);
   }
}

When we have something like this in our Request object 

typeDesc.setXmlType(new QName("http://deneme/ManagementTypes", ">CreateOrderRequest"));

10 Haziran 2020 Çarşamba

SHORTCUT

chmod -R 775 /home/wlsadmin/app/web/AP


git init
git add .
git commit -m "initial commit"
git remote add origin https://github.com/tayfunclk/forsquareCategory.git
git remote add origin https://github.com/tayfunclk/forsquareCategoryApi.git
git remote add origin https://github.com/tayfunclk/ticketsystem.git
git push -f origin master

--git push --force origin origin/deneme:master


--update--

git pull origin master
git add .
git commit -m "initial commit"
git push -f origin master

Bu Blogda Ara