/* * Copyright (c) 2019, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/* * @test * @bug 8226346 * @summary Check all output files for absolute path fragments * @requires !vm.debug * @run main AbsPathsInImage
*/ publicclass AbsPathsInImage {
// Set this property on command line to scan an alternate dir or file: // JTREG=JAVA_OPTIONS=-Djdk.test.build.AbsPathInImage.dir=/path/to/dir publicstaticfinal String DIR_PROPERTY = "jdk.test.build.AbsPathsInImage.dir"; privatestaticfinalboolean IS_WINDOWS = System.getProperty("os.name").toLowerCase().contains("windows"); privatestaticfinalboolean IS_LINUX = System.getProperty("os.name").toLowerCase().contains("linux");
private List<String> scanBytes(byte[] data, List<byte[]> searchPatterns) {
List<String> matches = new ArrayList<>(); for (int i = 0; i < data.length; i++) { for (byte[] searchPattern : searchPatterns) { boolean found = true; for (int j = 0; j < searchPattern.length; j++) { if ((i + j >= data.length || data[i + j] != searchPattern[j])) {
found = false; break;
}
} if (found) {
matches.add(new String(data, charsStart(data, i), charsOffset(data, i, searchPattern.length))); // No need to search the same string for multiple patterns break;
}
}
} return matches;
}
privateint charsStart(byte[] data, int startIndex) { int index = startIndex; while (--index > 0) { byte datum = data[index]; if (datum < 32 || datum > 126) { break;
}
} return index + 1;
}
privateint charsOffset(byte[] data, int startIndex, int startOffset) { int offset = startOffset; while (startIndex + ++offset < data.length) { byte datum = data[startIndex + offset]; if (datum < 32 || datum > 126) { break;
}
} return offset;
}
}
¤ Dauer der Verarbeitung: 0.13 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.