Nifi:How can i remove “.” from “.filename” in nifi custom processor

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Nifi:How can i remove “.” from “.filename” in nifi custom processor

sally

I have send updated file to directory used a logic of putFile but it save
file as i ".filenam.xml" and can't get it by getFile Processor how can
remove "." from this file, i have read that putFile makes it automatically i
mean adding dot in front of flowfile name, but how can i remove this dot?
final Path tempCopyFile =
rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
this is how it works in putFile how can i make same in my proessor without
adding "." to filename?



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Nifi:How can i remove “.” from “.filename” in nifi custom processor

Jeff
Sally,

The . in front of the filename is used while the contents of the file are
being written, so that the file will not be picked up by processors like
ListFile (if configured to watch the same directory to which files are
being written) until the writing is complete.  Can you confirm that the
complete file contents have been written, and the .filename is still
present in the directory?

On Thu, Oct 5, 2017 at 7:47 AM sally <[hidden email]> wrote:

>
> I have send updated file to directory used a logic of putFile but it save
> file as i ".filenam.xml" and can't get it by getFile Processor how can
> remove "." from this file, i have read that putFile makes it automatically
> i
> mean adding dot in front of flowfile name, but how can i remove this dot?
> final Path tempCopyFile =
>
> rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
> this is how it works in putFile how can i make same in my proessor without
> adding "." to filename?
>
>
>
> --
> Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/
>
Reply | Threaded
Open this post in threaded view
|

Re: Nifi:How can i remove “.” from “.filename” in nifi custom processor

sally
how can i see  that  flowfile  write is  already  finished  i have  renameTo
code  like  this  :
 final Path rootDirPath =
get("C://Users//user//Desktop//try2//nifi-1.3.0//1");
                final Path tempCopyFile =
rootDirPath.resolve("."+flowFile.getAttribute(CoreAttributes.FILENAME.key()));
                final Path dotCopyFile =tempCopyFile;
                Path tempDotCopyFile = null;
                tempDotCopyFile = dotCopyFile;

                final Path
copyFile=rootDirPath.resolve(flowFile.getAttribute(CoreAttributes.FILENAME.key()));
                Path finalCopyFile = copyFile;
                if (!Files.exists(rootDirPath)) {
                    if (true) {
                        Files.createDirectories(rootDirPath);
                    }
                }


                final Path finalCopyFileDir = finalCopyFile.getParent();
                if (Files.exists(finalCopyFileDir)) { // check if too many
files already
                    final int numFiles =
finalCopyFileDir.toFile().list().length;

                    if (numFiles >= 10) {
                        flowFile = session.penalize(flowFile);
                        logger.warn("Penalizing {} and routing to 'failure'
because the output directory {} has {} files, which exceeds the "
                                + "configured maximum number of files", new
Object[]{flowFile, finalCopyFileDir, numFiles});
                        session.transfer(flowFile, REL_FAILURE);
                        return;
                    }
                }
                session.exportTo(flowFile,dotCopyFile,false);

                //dotCopyFile.toFile().renameTo(finalCopyFile.toFile());

                logger.info("added {} to flow", new
Object[]{flowFile,flowFile1});
                boolean renamed = false;
                for (int i = 0; i < 10; i++) { // try rename up to 10 times.
                    if
(dotCopyFile.toFile().renameTo(finalCopyFile.toFile())) {
                        renamed = true;
                        break;// rename was successful
                    }
                    Thread.sleep(100L);// try waiting a few ms to let
whatever might cause rename failure to resolve
                }

                if (!renamed) {
                    if (Files.exists(dotCopyFile) &&
dotCopyFile.toFile().delete()) {
                        logger.debug("Deleted dot copy file {}", new
Object[]{dotCopyFile});
                    }
                    throw new ProcessException("Could not rename: " +
dotCopyFile);
                } else {
                    logger.info("Produced copy of {} at location {}", new
Object[]{flowFile, finalCopyFile});
                }



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/
Reply | Threaded
Open this post in threaded view
|

Re: Nifi:How can i remove “.” from “.filename” in nifi custom processor

sally
actually  it never  fiishes  writing process  i mean  exceptions  like this
can't rename  file ".conf.xml"



--
Sent from: http://apache-nifi-developer-list.39713.n7.nabble.com/