Java源码示例:com.fasterxml.sort.SortConfig
示例1
public SortedPathIterator(final Iterator<Path> iter) throws IOException {
SortConfig config = new SortConfig().withMaxMemoryUsage(1000000);
Sorter sorter = new TextFileSorter(config);
DataReader<byte[]> reader = new DataReader<byte[]>() {
@Override
public byte[] readNext() throws IOException {
if (!iter.hasNext()) {
return null;
}
return iter.next().toString().getBytes(StandardCharsets.UTF_8);
}
@Override
public void close() throws IOException {}
@Override
public int estimateSizeInBytes(byte[] item) { return item.length; }
};
this.sortedIter = sorter.sort(reader);
}
示例2
public void sortFile(File in, File out, Comparator<String> cmp) {
try {
long availMem = Runtime.getRuntime().maxMemory()
- (2048 * 1024 * 1024);
long maxMem = (availMem >> 1);
if (maxMem > MAX_HEAP_FOR_PRESORT) {
maxMem = MAX_HEAP_FOR_PRESORT;
} else if (maxMem < MIN_HEAP_FOR_PRESORT) {
maxMem = MIN_HEAP_FOR_PRESORT;
}
final TextFileSorter sorter = new TextFileSorter(
new SortConfig().withMaxMemoryUsage(maxMem));
sorter.sort(new FileInputStream(in), new PrintStream(out));
} catch (IOException e) {
e.printStackTrace();
}
}
示例3
public void sortFile(File in, File out) {
try {
long availMem = Runtime.getRuntime().maxMemory()
- (40 * 1024 * 1024);
long maxMem = (availMem >> 1);
if (maxMem > MAX_HEAP_FOR_PRESORT) {
maxMem = MAX_HEAP_FOR_PRESORT;
} else if (maxMem < MIN_HEAP_FOR_PRESORT) {
maxMem = MIN_HEAP_FOR_PRESORT;
}
final TextFileSorter sorter = new TextFileSorter(
new SortConfig().withMaxMemoryUsage(maxMem));
sorter.sort(new FileInputStream(in), new PrintStream(out));
} catch (IOException e) {
e.printStackTrace();
}
}
示例4
static Iterator<SortHelper.Entry> sort(final File logFile, final long start, final long end,
final HashType hashData, final long hashCapacity, final int hashSeed,
final long maxMemory) throws IOException {
SortConfig config = new SortConfig();
if (maxMemory > 0) {
config = config.withMaxMemoryUsage(maxMemory);
}
final EntryDataReaderFactory readerFactory = new EntryDataReaderFactory(hashCapacity);
Sorter<SortHelper.Entry>
sorter = new Sorter<>(config, readerFactory, ENTRY_DATA_WRITER_FACTORY, ENTRY_COMPARATOR);
return sorter.sort(new LogFileEntryReader(logFile, start, end, hashData, hashCapacity, hashSeed));
}
示例5
public TextFileShuffler() {
this(new SortConfig());
}
示例6
public TextFileShuffler(SortConfig config) {
//super(config, RawTextLineReader.factory(), RawTextLineWriter.factory(), new ShufflingComparator());
super(config, new CustomReaderFactory<byte[]>(), RawTextLineWriter.factory(), new ShufflingComparator());
}
示例7
private SortConfig getSortConfig (MergeTempFileProvider tmpFileProvider) {
long maxMemory = Long.parseLong(context.getServiceManager().getConfigurationService().getProperty("fdbsql.sort.memory"));
return new SortConfig().withTempFileProvider(tmpFileProvider).withMaxMemoryUsage(maxMemory);
}
示例8
public SplitFileSorter() {
this(new SortConfig());
}
示例9
public SplitFileSorter(SortConfig config)
{
super(config,
LineReader.factory(), LineWriter.factory(),
new SplitStringComparator());
}