1. Список говнокодов пользователя psvm

    Всего: 1

  2. Java / Говнокод #12601

    +77

    1. 01
    2. 02
    3. 03
    4. 04
    5. 05
    6. 06
    7. 07
    8. 08
    9. 09
    10. 10
    11. 11
    12. 12
    13. 13
    14. 14
    15. 15
    16. 16
    17. 17
    18. 18
    19. 19
    20. 20
    21. 21
    22. 22
    23. 23
    24. 24
    25. 25
    26. 26
    27. 27
    28. 28
    29. 29
    30. 30
    31. 31
    32. 32
    33. 33
    34. 34
    35. 35
    36. 36
    byte[] buffer = new byte[BUFFER_SIZE];
    ReadState readState = ReadState.BOUNDARY;
    
    InputStream input = request.getInputStream();
    int read = input.read(buffer);
    int pos = 0;
    
    // This is a fail-safe to prevent infinite loops from occurring in some environments
    int loopCounter = 20;
    
    while (read > 0 && loopCounter > 0) {
        for (int i = 0; i < read; i++) {
            switch (readState) {
                // Pos is calculated...
                case BOUNDARY: 
                case HEADERS: 
                case DATA: 
            }
        }
    
        if (pos < read) {
            // move the bytes that weren't read to the start of the buffer
            int bytesNotRead = read - pos;
            System.arraycopy(buffer, pos, buffer, 0, bytesNotRead);
            read = input.read(buffer, bytesNotRead, buffer.length - bytesNotRead);
    
            // Decrement loopCounter if no data was readable
            if (read == 0) {
                loopCounter--;
            }
    
            read += bytesNotRead;
        } else {
            read = input.read(buffer);
        }
    }

    Кусок исходников из недров JBoss Seam(наткнулся профайлером).
    Пацаны пофиксили багу с бесконечным циклом и 100 утилизацией CPU.
    Весь класс:
    https://www.java2s.com/Open-Source/Java/JBoss/jboss-seam-2.2.0/org/jboss/seam/web/MultipartRequestImpl.java.htm
    Версия с бесконечным циклом:
    http://www.docjar.com/html/api/org/jboss/seam/web/MultipartRequestImpl.java.html

    psvm, 16 Февраля 2013

    Комментарии (1)