yacy_search_server/source/de/anomic/tools/tarTools.java
orbiter ce1adf9955 serialized all logging using concurrency:
high-performance search query situations as seen in yacy-metager integration showed deadlock situation caused by synchronization effects inside of sun.java code. It appears that the logger is not completely safe against deadlock situations in concurrent calls of the logger. One possible solution would be a outside-synchronization with 'synchronized' statements, but that would further apply blocking on all high-efficient methods that call the logger. It is much better to do a non-blocking hand-over of logging lines and work off log entries with a concurrent log writer. This also disconnects IO operations from logging, which can also cause IO operation when a log is written to a file. This commit not only moves the logger from kelondro to yacy.logging, it also inserts the concurrency methods to realize non-blocking logging.

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@6078 6c8d7289-2bf4-0310-a012-ef5d649a1542
2009-06-15 21:19:54 +00:00

96 lines
3.1 KiB
Java

// tarTools.java
// (C) 2008 by David Wieditz; d.wieditz@gmx.de
// first published 21.05.2008 on http://yacy.net
//
// This is a part of YaCy, a peer-to-peer based web search engine
//
// $LastChangedDate: $
// $LastChangedRevision: $
// $LastChangedBy: $
//
// LICENSE
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package de.anomic.tools;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.zip.GZIPInputStream;
import com.ice.tar.TarEntry;
import com.ice.tar.TarInputStream;
import de.anomic.yacy.logging.Log;
public class tarTools {
public static InputStream getInputStream(final String tarFileName) throws Exception{
if(tarFileName.endsWith(".gz")){
return new GZIPInputStream(new FileInputStream(new File(tarFileName)));
}
return new FileInputStream(new File(tarFileName));
}
public static InputStream getInputStream(final File tarFileName) throws Exception{
return getInputStream(tarFileName.toString());
}
/**
* untar for any archive, overwrites existing data
* @param in use getInputStream() for convenience
* @param untarDir destination path
* @throws Exception (IOException or FileNotFoundException)
*/
public static void unTar(final InputStream in, final String untarDir) throws Exception{
Log.logInfo("UNTAR", "starting");
if(new File(untarDir).exists()){
final TarInputStream tin = new TarInputStream(in);
TarEntry tarEntry = tin.getNextEntry();
while(tarEntry != null){
final File destPath = new File(untarDir + File.separator + tarEntry.getName());
if (!tarEntry.isDirectory()) {
new File(destPath.getParent()).mkdirs(); // create missing subdirectories
final FileOutputStream fout = new FileOutputStream(destPath);
tin.copyEntryContents(fout);
fout.close();
} else {
destPath.mkdir();
}
tarEntry = tin.getNextEntry();
}
tin.close();
} else { // untarDir doesn't exist
Log.logWarning("UNTAR", "destination " + untarDir + " doesn't exist.");
}
Log.logInfo("UNTAR", "finished");
}
public static void main(final String args[]){
// @arg0 source
// @arg1 destination
if(args.length == 2){
try {
unTar(getInputStream(args[0]), args[1]);
} catch (final Exception e) {
System.out.println(e);
}
} else {
System.out.println("usage: <source> <destination>");
}
}
}